Help with creating new column inside a matrix with new data.

1 次查看(过去 30 天)
Dear matlab users
i have a matrix of 1511x65 double called x. it has 1511 rows and 65 columns...each column is representing a customer and the 1511 represnts 63 days of power usage with 1 hour for each data obtained. so 1511 / 24 = 63 days.
i made this code to make a graph for each or total of the customers with 24 hours of each customer. Meaning: u will see at clock 3 pm there will be alot of data on 1 row all occured in that time line but different day.
tid = [0:23]';
n = 0;
while(n<2) %%control how much of the data you wanna plot
n = n + 1;
for i=1:size(x,2)
k = x(:,n);
trow = 24;
tcol = ceil(length(x)/trow);
k1 = [k;0];
k1 = reshape(k1,trow,tcol);
k1 = mean(k1,2); %%taking the mean of the current chosen data from while loop
% plot(tid,k1)
% hold on
end
end
The first Question is now: it all works..but HOW do i make it so it creates 1 column for each of the customer for 24 hours...so the matrix in end is: 24x64.
the second question: what if i wanted to filter out weekends out of the data set and work seperately with week days and weekends.
i include hereby the data called x.
thanks for help

采纳的回答

Matt Tearle
Matt Tearle 2014-4-11
It looks like you have to pad with 0 to get 63 full days (you have 62 days + 23 hours), so why not just do that at the beginning, then work with the whole data set as a 3-day array of hour-by-day-by-customer:
ncust = size(x,2);
% pad data with one extra row
x = [x;zeros(1,ncust)];
% reshape data into hour/day/customer
x = reshape(x,24,[],ncust);
% average across days
k1 = squeeze(mean(x,2));
% plot the average for the first five customers
plot(0:23,k1(:,1:5))
% Split data into weekdays (2:6) and weekends (1 & 7)
daynum = mod(1:size(x,2),7);
isweekend = (daynum==1) | (daynum==0);
x_weekday = x(:,~isweekend,:);
x_weekend = x(:,isweekend,:);
At the end, I'm assuming that the days are S/M/T/W/T/F/S. If not, change the 0 and/or 1 in the command isweekend = (daynum==1) | (daynum==0);
  1 个评论
awda
awda 2014-4-12
i must say this was awesome :)..thanks for spending time to help me man, i really do appreciate it :).
you saved my thesis..:)..

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by