annual, seasonal mean from monthly time series
7 views (last 30 days)
Show older comments
Yogesh Kumkar
on 16 Mar 2022
Answered: Steven Lord
on 16 Mar 2022
I have a monthly mean time series netcdf data.
I want to get annual and seasonal mean (4 seasons). Here is my code, but I am not really able to get what I want.
MySeas = {'JJA','SON','DJF', 'MAM', 'ANNUAL'};
s = size(tERA); % data starts from 09 2008 til 08 2012
% s = 237 77 12 48
for ss=1:length(MySeas)
curSeas = MySeas{ss};
switch curSeas
case {'Annual'} % mean of 09 to 08 of each year, 12 months
tANNx = squeeze(mean(reshape(tERA,[s(1:3),12,s(4)/12]),4)); % size: 237,77,12,4
tANN = mean(tANNx,4);
case {'JJA'} %mean of 06, 07, 08 of each year
tJJAx = squeeze(mean(reshape(tERA,[s(1:3),3,s(4)/12]),4)); % size: 237,77,12,4
tJJA = mean(tJJAx,4);
case {'SON'} % mean of 09, 10, 11 of each year
tSONx = squeeze(mean(reshape(tERA,[s(1:3),3,s(3)/12]),4)); % size: 237,77,12,4
tSON = mean(tSONx,4);
case {'DJF'} %mean of 12, 01, 02 of each year
tDJFx = squeeze(mean(reshape(tERA,[s(1:3),3,s(3)/12]),4)); % size: 237,77,12,4
tDJF = mean(tDJFx,4);
case {'MAM'} %mean of 03, 04, 05 of each year
tMAMx = squeeze(mean(reshape(tERA,[s(1:3),3,s(3)/12]),4)); % size: 237,77,12,4
tMAM = mean(tMAMx,4);
otherwise
txt='not applicable: ';
end
end
Please correct the squeeze statements. Thank you.
0 Comments
Accepted Answer
Cris LaPierre
on 16 Mar 2022
I don't know much about your data, but I would see if groupsummary works. If you have datetime info in your data, you can use the 'groupbin' input to specify a way to automatically group your data and then apply method(s) to each group.
0 Comments
More Answers (1)
Steven Lord
on 16 Mar 2022
Consider using groupsummary with the season data as your grouping variable.
0 Comments
See Also
Categories
Find more on Web Services in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!