Average of variables in timetable belonging to the same day over several years
12 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ziad Sari El Dine
el 24 de Ag. de 2022
Comentada: Ziad Sari El Dine
el 25 de Ag. de 2022
Hello, I have a timetable, TT(681-by-19), with unevenly spaced daily data from 2010 to 2020 and 19 variables (there might be days that do not occur every year in addition to gaps where entire months are missing). I want to calculate the mean of the variables that correspond to the same day throughout the different years. For example I want to calculate the mean of each of the 19 variables that correspond to 25-oct 2010, 25-oct 2011, ..., 25-oct 2020 and so on for the different dates. That way I would have each unique day-month occurring only once in the output.
Note: I also have the dates seperately as a datetime array and as a numeric array in the form of yyyymmdd (681-by-1) and the 19 variables in a numeric array (681-by-19), if there is a simpler method without the use of the timetable.
Thanks for any assistance.
0 comentarios
Respuesta aceptada
Peter Perkins
el 25 de Ag. de 2022
Ziad, it seems that "dayofyear" is using "serial day number of year", and as you found, is lumping 29-Feb's with the non-leap 1-Mar's, etc. What you want is to group by month/day. If you use the month and day of month as grouping vars, you get what you want:
dt = [datetime(2012,2,27:31) ...
datetime(2013,2,27:30) ...
datetime(2014,2,27:30) ...
datetime(2015,2,27:30) ...
datetime(2016,2,27:31)]';
x = dt.Day;
tt = timetable(x,RowTimes=dt)
tt.Month = string(month(tt.Time,"name"));
tt.Day = day(tt.Time,"dayofmonth");
means = groupsummary(tt,["Month" "Day"],"mean","x")
Más respuestas (1)
Ver también
Categorías
Más información sobre Data Type Conversion 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!