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

조회 수: 3 (최근 30일)
awda
awda 2014년 4월 11일
댓글: awda 2014년 4월 12일
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에서 Calendar에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by