필터 지우기
필터 지우기

seasonal mean for each year based on the sample code

조회 수: 6 (최근 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 CenterFile Exchange에서 Calendar에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by