Mean for particular seasons over 32 yrs..say January to March(1:3),4:6,7:9,10:12
조회 수: 1 (최근 30일)
이전 댓글 표시
I want to take the mean season wise..say for Winter, Spring, Summer and Autumn.. and then need to show over a period of 32 years ..how the seasonal mean is changing.
datacoord = reshape(data, 361,361,4);
lat = squeeze(datacoord(:,:,3));
long = squeeze(datacoord(:,:,4));
%m_proj('Azimuthal Equal-area');
m_proj('stereographic','lat',90,'long',30,'radius',22);
m_grid('xtick',12,'tickdir','out','ytick',[65 70 75 80 85 90],'linest','-');
m_coast('patch',[.7 .7 .7],'edgecolor','r');
m_elev('contour',[ ],'edgecolor',' ');
for y=1979:2012,
% open binary file for
% Polar Pathfinder Daily 25 km EASE-Grid Sea Ice Motion Vectors, Version 2
folderpath = 'C:\Users\Documents\MATLAB\Mean_months\';
stryear = num2str(y);
filepath = fullfile(folderpath,stryear);
files = dir(fullfile(filepath,'\icemotion.mean.*.n.v02.bin') );
files = {files.name};
Umean = [];
Vmean = [];
for i=1:numel(files),
disp(files{i});
filename = fullfile(filepath,files{i});
fid = fopen(filename);
rawdata = fread(fid,[361, inf],'int16');
fclose(fid);
% reshape it into a [3x361x361] matrix
dd = reshape(rawdata,[3, 361, 361]);
% change 3d matrix to simple matrix, and divide by 10 to get cm/second
u = squeeze(dd(1,:,:)) ./ 10;
v = squeeze(dd(2,:,:)) ./ 10;
% Change the data values from cm/s to m/second by multiplying it with 1/100
u = u*1/100;
v = v*1/100;
end
find(lat < 1 | lat ~= fix(lat))
find(long < 1 | long ~= fix(long))
i = lat;
j = long;
k = 1:length(1979:2012);
u = u(i,j,k);
v = v(i,j,k);
yrlst = 1979:2012;
wintlst = 1:3;
for i = 1:length(yrlst)
tempwint = wintlst +(i-1)*12;
tmpu = squeeze(nanmean(u(:,:,tempwint),3));
tmpv = squeeze(nanmean(v(:,:,tempwint),3));
for j = 1:size(tmpu,1)
k = 1:size(tmpu,2)
tuwint(j,k,i) = tmpu(j,k);
tvwint(j,k,i) = tmpv(j,k);
end
end
end
댓글 수: 0
답변 (1개)
Chad Greene
2015년 9월 13일
It's hard to decipher your nested loops, but here's how I'd tackle it. I'll assume you have a big 3D matrix U whose dimensions correspond to (lon x lat x time) or (gridx x gridy x time) or something of the like. You probably also have a 3D matrix of the same size V for zonal motion, and I'll assume you have an array t and length(t) = size(U,3).
1. Get t into components of year, month, and day:
[year,month,day] = datevec(t);
2. The downsample_ts function computes monthly means, so we'll lie to downsample_ts and tell it that all December and February data happened in January.
month(month==12) = 1;
month(month==2) = 1;
Do the same for the other seasons, i.e.,
month(month==3) = 4;
month(month==5) = 5;
And when you do the same for the other seasons, you should get
unique(month)
= [1, 4, 7, 10];
Create a new fake t2 vector:
t2 = datenum([year,month,day]);
Then a 32 year record of seasonal means can be obtained by
[Umean,tmean] = downsample_ts(U,t,'monthly','mean');
Vmean = downsample_ts(V,t,'monthly','mean');
Dimensions of Umean and Vmean will be size(U,1) x size(U,2) x 128 because 4 seasons times 32 years is 128. All DJF data will be given by
Umean(:,:,tmean==1);
And if you want to get a linear trend map of DJF seasonal averages over 32 years you could do
U_djf_trend = trend(Umean(:,:,tmean==1),1,3);
댓글 수: 4
Max Reinicke
2016년 5월 22일
Dear Chad,
How can I go back from the cryptic t2=datenum values to f.e. the year of the winter season?
so to have two columns of: year;season;Umean
Thanks for the great function and help!
Walter Roberson
2020년 9월 7일
Dwaipayan Chatterjee comments to Chad Greene:
[Umean,tmean] = downsample_ts(U,t,'monthly','mean');
Vmean = downsample_ts(V,t,'monthly','mean');
At this stage I suppose instead of 't', 't2' should be used
참고 항목
카테고리
Help Center 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!