How to average a time series with different length by days?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Kristine
el 27 de Jul. de 2015
Comentada: Kristine
el 27 de Jul. de 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 comentario
Jon
el 27 de Jul. de 2015
Editada: Jon
el 27 de Jul. de 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.
Respuesta aceptada
Walter Roberson
el 27 de Jul. de 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 comentarios
Walter Roberson
el 27 de Jul. de 2015
[unique_rows, ~, idx] = unique(TS(:,1:3),'rows');
Más respuestas (0)
Ver también
Categorías
Más información sobre Dates and Time en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!