0001 function res=rebin(a,n);
0002
0003
0004
0005
0006
0007
0008
0009
0010 s=size(a);
0011
0012 if (mod(s(1)/n,2)~=0 | mod(s(2)/n,2)~=0),
0013 disp('Cannot rebin, the dimensions of the matrix and n are not compatible');
0014 break
0015 end
0016
0017 res=zeros(s(1)/n,s(2)/n);
0018
0019 for m=1:s(1)/n,
0020 for l=1:s(2)/n,
0021 if sum(sum(~isnan(a((m-1)*n+1:m*n,(l-1)*n+1:l*n))))~=0,
0022 res(m,l)=sum(...
0023 sum(...
0024 ~isnan(...
0025 a((m-1)*n+1:m*n,(l-1)*n+1:l*n)...
0026 ).*...
0027 a((m-1)*n+1:m*n,(l-1)*n+1:l*n)...
0028 )...
0029 )...
0030 /sum(sum(~isnan(a((m-1)*n+1:m*n,(l-1)*n+1:l*n))));
0031 else
0032 res(m,l)=NaN;
0033 end
0034
0035 end
0036 end
0037
0038
0039
0040
0041
0042
0043
0044