Timetable_Averaging values from each month
Mostrar comentarios más antiguos
Timetable Averaging values from each month(Jan-Dec) from all years between 2000-2020. So I would like to have 12 USDM_Index values; one for each month over the 21 years
3 comentarios
Scott MacKenzie
el 21 de Oct. de 2021
If your data are in a timetable, then use the retime function with 'monthly' as the newTimeStep. Check the documentation for retime for some examples.
Leulaye Maskal
el 21 de Oct. de 2021
Ritesh
el 4 de Mayo de 2023
monthlyavg = groupsummary(b, 'month', 'monthofyear', 'mean');
%here b is your table
Respuestas (2)
Kelly Kearney
el 21 de Oct. de 2021
I don't believe you can use retime to build a climatology; for that, I usually use the splitapply function. Unfortunately, splitapply's syntax for tables and timetables is very clunky (there's no easy way to apply the same function to all variables), hence my casting to and from arrays in the following example:
% The original timetable
T = timetable(datetime(2000,1:24,1)', rand(24,1), rand(24,1), ...
'VariableNames', {'USDM_index', 'other'});
% Calculate climatological monthly average
[g, mn] = findgroups(month(T.Time));
xclim = splitapply(@(x) mean(x,1), table2array(T), g);
% Reformat to timetable
refyr = min(year(T.Time)); % ... or whatever you want
Tclim = array2timetable(xclim, 'RowTimes', datetime(refyr,mn,1), ...
'VariableNames', T.Properties.VariableNames);
Use groupsummary with 'monthofyear' binning
T = timetable(datetime(2000,1:(12*21),1)', rand(12*21,1), 'VariableNames', {'USDM_index'});
S = groupsummary(T, 'Time', 'monthofyear', 'mean')
1 comentario
Leulaye Maskal
el 22 de Oct. de 2021
Categorías
Más información sobre Tables en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!