How to average a time series with different length by days?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Kristine
am 27 Jul. 2015
Kommentiert: Kristine
am 27 Jul. 2015
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 Kommentar
Jon
am 27 Jul. 2015
Bearbeitet: Jon
am 27 Jul. 2015
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.
Akzeptierte Antwort
Walter Roberson
am 27 Jul. 2015
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(:)];
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Dates and Time finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!