mean_congrid

PURPOSE ^

MEAN_CONGRID - average the values around a pixel

SYNOPSIS ^

function res=mean_congrid(a,n,choice);

DESCRIPTION ^

MEAN_CONGRID - average the values around a pixel

   INPUT a,n,choice, where a is the matrix, and n the size of the area averaged around
   one pixel, odd number. choice=1 if the NaN values remain NaN values.

   Usage:
      res=mean_congrid(a,n,choice)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function res=mean_congrid(a,n,choice);
0002 %MEAN_CONGRID - average the values around a pixel
0003 %
0004 %   INPUT a,n,choice, where a is the matrix, and n the size of the area averaged around
0005 %   one pixel, odd number. choice=1 if the NaN values remain NaN values.
0006 %
0007 %   Usage:
0008 %      res=mean_congrid(a,n,choice)
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

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