# Timetable_Averaging values from each month

12 vues (au cours des 30 derniers jours)
Leulaye Maskal le 21 Oct 2021
Commenté : Ritesh le 4 Mai 2023
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 commentairesAfficher 1 commentaire plus ancienMasquer 1 commentaire plus ancien
Leulaye Maskal le 21 Oct 2021
I have tried that but its gives me the mean for each month within each yearh so I end up wit 12 * 21 for each month
Ritesh le 4 Mai 2023
monthlyavg = groupsummary(b, 'month', 'monthofyear', 'mean');

Connectez-vous pour commenter.

### Réponses (2)

Kelly Kearney le 21 Oct 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);
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

Duncan Po le 22 Oct 2021
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')
S = 12×3 table
monthofyear_Time GroupCount mean_USDM_index ________________ __________ _______________ 1 21 0.44367 2 21 0.44095 3 21 0.52971 4 21 0.66029 5 21 0.45509 6 21 0.59956 7 21 0.56916 8 21 0.49774 9 21 0.49873 10 21 0.49883 11 21 0.48883 12 21 0.56189
##### 1 commentaireAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens
Leulaye Maskal le 22 Oct 2021
I tried this but i keep getting a timetavble error

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Tables dans Help Center et File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by