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

1 view (last 30 days)
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

Accepted Answer

Matt Tearle
Matt Tearle on 11 Apr 2014
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 Comment
awda
awda on 12 Apr 2014
i must say this was awesome :)..thanks for spending time to help me man, i really do appreciate it :).
you saved my thesis..:)..

Sign in to comment.

More Answers (0)

Categories

Find more on Dates and Time in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!