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

2 visualizzazioni (ultimi 30 giorni)
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 Commento
Jon
Jon il 27 Lug 2015
Modificato: Jon il 27 Lug 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.

Accedi per commentare.

Risposta accettata

Walter Roberson
Walter Roberson il 27 Lug 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(:)];
  3 Commenti

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Dates and Time in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by