calculate mean value for each hour of the day from a time series

3 Ansichten (letzte 30 Tage)
Richard
Richard am 19 Jul. 2012
I would like to calculate the hourly mean values for the following time series:
DateTime = datestr(datenum('2011-01-01 00:00','yyyy-mm-dd HH:MM'):1/24:...
datenum('2011-12-31 23:00','yyyy-mm-dd HH:MM'),...
'yyyy-mm-dd HH:MM');
DOY = datenum(cellstr(DateTime)) - datenum(2011,0,0);
data = 1 + (30-1).*rand(length(DOY),1);
DOY defines the decimal day of year and data represents the example data set. From this, I would to generate an array of 24 values, where each value corresponds to the mean value for that particular hour of the day. so the first value should be the mean of the first value in 'data' and every 25 rows following each (where each 24 rows corresponds to a different day)

Antworten (1)

Miro
Miro am 19 Jul. 2012
for example like this:
t = yourstartdate;
dt = 1/24;
while t < yourenddate
datatmp = mean(data(Tarray <t+dt & Tarray >t));
Dataout = [Dataout;datatmp]
t=t+dt;
end
so what you need to have is the Tarray, that contains the datenums of all the data (so it has the same length as data).

Community Treasure Hunt

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

Start Hunting!

Translated by