annual, seasonal mean from monthly time series

5 次查看(过去 30 天)
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.

采纳的回答

Cris LaPierre
Cris LaPierre 2022-3-16
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.

更多回答(1 个)

Steven Lord
Steven Lord 2022-3-16
Consider using groupsummary with the season data as your grouping variable.

类别

Help CenterFile Exchange 中查找有关 R Language 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by