11 |
% - prepare list of records to average (depending on myYear, lYear and nYears) |
% - prepare list of records to average (depending on myYear, lYear and nYears) |
12 |
% - in case when lYear<2 we use records as years |
% - in case when lYear<2 we use records as years |
13 |
% |
% |
14 |
%by assumption: |
%by assumption: |
15 |
% - the time dimension is last in myFld, and matches the length of myTimes |
% - the time dimension is last in myFld, and matches the length of myTimes |
16 |
|
|
17 |
%determine the number of records in one year (lYear) |
%determine the number of records in one year (lYear) |
27 |
%determine records that correspond to myYear, which |
%determine records that correspond to myYear, which |
28 |
% may be 'first','last',n (an integer) or 'all' |
% may be 'first','last',n (an integer) or 'all' |
29 |
if ischar(myYear); |
if ischar(myYear); |
30 |
if strcmp(myYear,'first'); |
if strcmp(myYear,'first'); |
31 |
recInAve=[1:lYear]; |
recInAve=[1:lYear]; |
32 |
elseif strcmp(myYear,'last'); |
elseif strcmp(myYear,'last'); |
33 |
recInAve=[1:lYear]+(nYears-1)*lYear; |
recInAve=[1:lYear]+(nYears-1)*lYear; |
34 |
elseif strcmp(myYear,'all'); |
elseif strcmp(myYear,'all'); |
35 |
recInAve=[1:nYears*lYear]; |
recInAve=[1:nYears*lYear]; |
36 |
else; |
else; |
37 |
error('inconsistent specification of myYear'); |
error('inconsistent specification of myYear'); |
38 |
end; |
end; |
39 |
elseif (myYear>=1)&(myYear<=nYears); |
elseif (myYear>=1)&(myYear<=nYears); |
40 |
recInAve=[1:lYear]+(myYear-1)*lYear; |
recInAve=[1:lYear]+(myYear-1)*lYear; |
41 |
else; |
else; |
42 |
error('inconsistent specification of myYear'); |
error('inconsistent specification of myYear'); |
43 |
end; |
end; |
44 |
nRecs=length(recInAve); |
nRecs=length(recInAve); |
45 |
|
|
46 |
%determine last dimension, which need to match the length myTimes |
%determine last dimension, which need to match the length myTimes |
47 |
if strcmp(class(myFld),'gcmfaces'); nDim=size(myFld{1}); else; nDim=size(myFld); end; |
if strcmp(class(myFld),'gcmfaces'); nDim=size(myFld{1}); else; nDim=size(myFld); end; |
48 |
if nDim(end)~=length(myTimes); error('last dimensopn should match the length of myTimes'); end; |
if length(myTimes)>1; |
49 |
nDim=length(nDim); tt=''; for jj=1:nDim-1; tt=[tt ':,']; end; |
if nDim(end)~=length(myTimes); |
50 |
|
error('last dimension should match the length of myTimes'); |
51 |
|
end; |
52 |
|
nDim=length(nDim); tt=''; for jj=1:nDim-1; tt=[tt ':,']; end; |
53 |
|
else; |
54 |
|
nDim=length(nDim)+1; tt=''; for jj=1:nDim-1; tt=[tt ':,']; end; |
55 |
|
end; |
56 |
|
|
57 |
%compute time mean: |
%compute time mean: |
58 |
eval(['myMean=mean(myFld(' tt 'recInAve),nDim);']); |
eval(['myMean=mean(myFld(' tt 'recInAve),nDim);']); |
59 |
|
|
60 |
%compute anomaly: |
%compute anomaly: |
61 |
if nargout>1; |
if nargout>1; |
62 |
myAnom=myFld-repmat(myMean,[ones(1:nDim-1) length(myTimes)]); |
myAnom=myFld-repmat(myMean,[ones(1:nDim-1) length(myTimes)]); |
63 |
end; |
end; |
64 |
|
|