Home > matutils > outlier.m

outlier

PURPOSE ^

function flag=outlier(pt,nsig,epsil)

SYNOPSIS ^

function flag=outlier(pt,nsig,epsil)

DESCRIPTION ^

 function flag=outlier(pt,nsig,epsil)

 flag points that is 'nsig' sigmas away from the mean.  the returned
 flag array is NOT bit oriented.

 if the std is smaller than epsil, nothing will get flagged.  epsil
 default value is 0.01

 Michael Loh

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function flag=outlier(pt,nsig,epsil)
0002 
0003 % function flag=outlier(pt,nsig,epsil)
0004 %
0005 % flag points that is 'nsig' sigmas away from the mean.  the returned
0006 % flag array is NOT bit oriented.
0007 %
0008 % if the std is smaller than epsil, nothing will get flagged.  epsil
0009 % default value is 0.01
0010 %
0011 % Michael Loh
0012 
0013 if (~exist('epsil'))
0014   epsil=0.01;
0015 end
0016 
0017 % initialize flag array
0018 flag=zeros(size(pt));
0019 
0020 % look for single points driving the rms WAY up
0021 for i=1:length(pt)
0022   x=pt;x(i)=NaN;
0023   r(i)=nanstd(x);
0024 end
0025 f=find(r/mean(r)<.5);
0026 pt(f)=NaN;flag(f)=1;
0027 
0028 % exit if the variance is tiny
0029 sig=nanstd(pt);
0030 if (sig<epsil)
0031   return;
0032 end
0033 
0034 % flagflagflag
0035 dif=abs(pt-repmat(nanmean(pt,1),[size(pt,1) ones(1,3)]));
0036 f=find(dif>=sig*nsig);
0037 
0038 flag(f)=1;

Generated on Sun 14-Jun-2015 17:12:45 by m2html © 2005