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

4 次查看(过去 30 天)
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)

回答(1 个)

Miro
Miro 2012-7-19
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).

类别

Help CenterFile Exchange 中查找有关 Dates and Time 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by