0001 function res=mean_congrid(a,n,choice);
0002
0003
0004
0005
0006
0007
0008
0009
0010 s=size(a);
0011 aa=a;
0012 pos=find(isnan(aa));
0013 aa(pos)=0;
0014
0015 if (mod(n,2)==0),
0016 disp('Cannot rebin, the dimensions of the matrix and n are not compatible');
0017 break
0018 end
0019 mm=(n-1)/2;
0020
0021 res=zeros(s(1),s(2));
0022
0023 for m=mm+1:s(1)-mm,
0024 if mod(m,10)==0,
0025 disp(m/s(1)*100);
0026 end
0027
0028 for l=mm+1:s(2)-mm,
0029
0030
0031 if sum(sum(~isnan(a(m-mm:m+mm,l-mm:l+mm))))~=0,
0032 res(m,l)=sum(...
0033 sum(...
0034 ~isnan(...
0035 a(m-mm:m+mm,l-mm:l+mm)...
0036 ).*...
0037 aa(m-mm:m+mm,l-mm:l+mm)...
0038 )...
0039 )...
0040 /sum(sum(~isnan(a(m-mm:m+mm,l-mm:l+mm))));
0041 else
0042 res(m,l)=NaN;
0043 end
0044
0045 end
0046 end
0047
0048 if choice==1,
0049 pos=find(isnan(a));
0050 res(pos)=NaN;
0051 end
0052
0053
0054
0055
0056
0057
0058
0059