seasonal mean for each year based on the sample code
Afficher commentaires plus anciens
I am running following code for monthly and seasonal output. Now, I wantd to get seasonal output for each year (e.g.720x57x41 double). So, that I may get "spring", "summer", "autumn", "winter" 1982, 1983, 1984..... ect and save output each season seperately. It would be great if any one help me to modify or re-write the code.
% Generating date matrix
date_used=datevec(datenum(1982,1,1):datenum(2022,12,31));
% Determining land index
land_index=isnan(nanmean(mhw_ts,3));
% Monthly
mhwday_month=NaN(size(mhw_ts,1),size(mhw_ts,2),12); % lon-lat-month
mhwint_month=NaN(size(mhw_ts,1),size(mhw_ts,2),12); % lon-lat-month
for i=1:12
index_used=date_used(:,2)==i;
mhwday_month(:,:,i)=sum(~isnan(mhw_ts(:,:,index_used)),3,'omitnan')./(2022-1982+1);
mhwint_month(:,:,i)=mean(mhw_ts(:,:,index_used),3,'omitnan');
end
mhwday_month(repmat(land_index,1,1,12))=nan;
% mhwday_month is the average number of MHW days in each month during
% 1993-2016
% mhwint_month is the average intensity of MHW days in each month during
% 1993-2016
% Seasonal
% Determining austral seasons
% SPR-SON SUM-DJF AUT-MAM WIN-JJA
seas=[9 10 11;...
12 1 2;...
3 4 5;...
6 7 8];
mhwday_seas=NaN(size(mhw_ts,1),size(mhw_ts,2),4); % lon-lat-seasons
mhwint_seas=NaN(size(mhw_ts,1),size(mhw_ts,2),4); % lon-lat-seasons
for i=1:4
index_used=ismember(date_used(:,2),seas(i,:));
mhwday_seas(:,:,i)=sum(~isnan(mhw_ts(:,:,index_used)),3,'omitnan')./(3*(2022-1982+1));
mhwint_seas(:,:,i)=mean(mhw_ts(:,:,index_used),3,'omitnan');
end
mhwday_seas(repmat(land_index,1,1,4))=nan;
1 commentaire
Gurumoorthi K
le 3 Juil 2023
Réponses (1)
Peter Perkins
le 17 Juil 2023
0 votes
As in your other post, I can't follow youre code, but my strong recommendation is to read in your data using readtimetable, and then use groupsummary or retime. It's one line of code to compute yearly or monthly summaries.
Catégories
En savoir plus sur Weather and Atmospheric Science dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!