フィルターのクリア

seasonal mean for each year based on the sample code

7 ビュー (過去 30 日間)
Gurumoorthi K
Gurumoorthi K 2023 年 7 月 3 日
回答済み: Peter Perkins 2023 年 7 月 17 日
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 件のコメント
Gurumoorthi K
Gurumoorthi K 2023 年 7 月 3 日
Please find the full code.
Complete .zip can be found from: https://github.com/ZijieZhaoMMHW/m_mhw1.0

サインインしてコメントする。

回答 (1 件)

Peter Perkins
Peter Perkins 2023 年 7 月 17 日
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.

カテゴリ

Help Center および File ExchangeCalendar についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by