rebin

PURPOSE ^

REBIN - average values of a matrix by bloc

SYNOPSIS ^

function res=rebin(a,n);

DESCRIPTION ^

REBIN - average values of a matrix by bloc

   INPUT a,n, where a is the matrix, and n the size of the area averaged around
   one pixel

   Usage:
      res=rebin(a,n)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function res=rebin(a,n);
0002 %REBIN - average values of a matrix by bloc
0003 %
0004 %   INPUT a,n, where a is the matrix, and n the size of the area averaged around
0005 %   one pixel
0006 %
0007 %   Usage:
0008 %      res=rebin(a,n)
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

Generated on Sun 29-Mar-2009 20:22:55 by m2html © 2003