How to average a time series with different length by days?

2 次查看(过去 30 天)
Hi.
I want to average all the hours from one day into one. So that all the values from one day is averaged together. Any suggestions would be of great help!
- Kristine
My time series looks like this:
Year Month Day Hour Minute Second PM2.5
2009 5 4 22 0 0 15
2009 5 4 23 0 0 20
2009 5 5 0 0 0 16
2009 5 5 1 0 0 16
2009 5 5 2 0 0 16
2009 5 5 3 0 0 16
2009 5 5 4 0 0 17
2009 5 5 5 0 0 17
2009 5 5 6 0 0 21
2009 5 5 7 0 0 17
2009 5 5 8 0 0 20
2009 5 5 9 0 0 18
2009 5 7 15 0 0 13
2009 5 7 16 0 0 17
2009 5 7 17 0 0 18
  1 个评论
Jon
Jon 2015-7-27
编辑:Jon 2015-7-27
Not sure what PM2.5 is, but you can convert your dates to datenumbers (see http://www.mathworks.com/help/matlab/ref/datenum.html) and then do the averaging.
DateNumber = datenum(Y,M,D,H,MN,S)
You can use a for loop to find where the day changes and do the averaging within that window. You can also use indexing and logical statements to avoid the for loop.

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2015-7-27
Assuming your data is named TS
[unique_rows, ~, idx] = unique(TS(:,1:4),'rows');
daily_av = accumarray(idx(:), TS(:,7), [], @mean);
avg_TS = [unique_rows, daily_av(:)];

更多回答(0 个)

类别

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