How to subtract mean daily values from hourly data?
Show older comments
So I have flow data in an hourly time period, I was able to calculate the daily mean flow of these hourly values. Now I want to subtract the hourly flow values from the daily flow values to see how much change there is from the mean on a hourly basis.
Here is what I have so far:
Dates=datevec(DateandTime);
% Group by day
[unDates, ~, subs] = unique(Dates(:,1:3),'rows');
% Accumulate by day
AVG=[unDates accumarray(subs, Flow, [], @mean)];
f=AVG(:,4);
t=datenum(AVG(:,1:3));
figure
plot (x,y,t,f,'r')
legend('Hourly Flow','Daily Flow','location','best');
datetick ('x', 'mm-dd-yy', 'keepticks')
xlabel('Time');
ylabel('Flow [cfs]');
title('Daily Flow');
% axis tight
%%Difference from average flow
figure
n=datenum(AVG(:,1:3));
if n~=x
DeltaFlow=Flow-AVG(:,4);
end
I keep getting an error matrix do not agree.
9 Comments
Geoff Hayes
on 4 Sep 2014
Jen - which line throws the error? Is it
DeltaFlow=Flow-AVG(:,4);
If it is, then check the dimensions of Flow. I'm pretty sure that AVG(:,4) will be a mx1 column (where m is the number of rows in AVG) and so Flow will also have to be an mx1 column in order for the subtraction to succeed. For an operation of this sort (subtraction) the two matrices must have the same dimension.
jen
on 4 Sep 2014
Geoff Hayes
on 4 Sep 2014
So you see the problem then - you are comparing a 348x1 matrix with a 3329x1 matrix. Does n correspond to the daily flow, and x to the hourly flow? How do you wish to compare the two? If one is a subset of the other, or..?
It's not clear to me what you mean by make it match the dates to the daily values. The ~= is the "not equals" operator.
jen
on 4 Sep 2014
ccs
on 12 Feb 2015
Can someone please assist me on this: I have data for about 3 year (7 households electrical consumption). I am supposed to write a program in matlab that allows me to select any data (household, dates, etc) and calculate (and plot) daily, weekly average, weekend average, etc. Last time i used matlab was almost 4 years ago.......can someone please give and advise me on a good start?
Thanks everyone in advance.
ccs
on 12 Feb 2015
I have data of every second (huge!)and would like to use two seconds as mean time base
Geoff Hayes
on 12 Feb 2015
Sesilia - please create a new question for this problem.
Ok. Geoff Hayes, thanks, that was too messy. I think this one below is more clear.
I want to generate a power consumption graph. I have measured data (power, energy) for every two seconds, for say three year.
Challenge: to write a time defined program that plots every measurement (scatter) for any given day or days (between 00:00 & 24:00).
I hope this is clear....requests for more clarity are welcome.
Thank you all
ccs
on 18 Feb 2015
Sorry Geoff Hayes, I get what you meant now.
I created a new question, thanks for your guide.
Appreciated. :)
Accepted Answer
More Answers (0)
Categories
Find more on Data Type Conversion 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!