Home > GLMdenoise > utilities > filterout.m

filterout

PURPOSE ^

function [f,idx] = filterout(m,elt,mode)

SYNOPSIS ^

function [f,idx] = filterout(m,elt,mode)

DESCRIPTION ^

 function [f,idx] = filterout(m,elt,mode)

 <m> is a matrix
 <elt> is a number (can be NaN when <mode>==0)
 <mode> (optional) is
   0 means ~=
   1 means >
   2 means <
   3 means >=
   4 means <=
   default: 0.

 return <m> as a horizontal vector.  when <mode> is
   0, return elements ~= <elt>
   1, return elements > <elt>
   2, return elements < <elt>
   3, return elements >= <elt>
   4, return elements <= <elt>
 also return <idx> as a logical matrix the same size as <m> 
 indicating which ones we pulled out.

 example:
 isequal(filterout([1 2 3],2),[1 3])

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [f,idx] = filterout(m,elt,mode)
0002 
0003 % function [f,idx] = filterout(m,elt,mode)
0004 %
0005 % <m> is a matrix
0006 % <elt> is a number (can be NaN when <mode>==0)
0007 % <mode> (optional) is
0008 %   0 means ~=
0009 %   1 means >
0010 %   2 means <
0011 %   3 means >=
0012 %   4 means <=
0013 %   default: 0.
0014 %
0015 % return <m> as a horizontal vector.  when <mode> is
0016 %   0, return elements ~= <elt>
0017 %   1, return elements > <elt>
0018 %   2, return elements < <elt>
0019 %   3, return elements >= <elt>
0020 %   4, return elements <= <elt>
0021 % also return <idx> as a logical matrix the same size as <m>
0022 % indicating which ones we pulled out.
0023 %
0024 % example:
0025 % isequal(filterout([1 2 3],2),[1 3])
0026 
0027 % input
0028 if ~exist('mode','var') || isempty(mode)
0029   mode = 0;
0030 end
0031 
0032 % do it
0033 switch mode
0034 case 0
0035   if isnan(elt)
0036     idx = ~isnan(m);
0037   else
0038     idx = m~=elt;  % note that Inf and -Inf are okay here
0039   end
0040 case 1
0041   idx = m>elt;
0042 case 2
0043   idx = m<elt;
0044 case 3
0045   idx = m>=elt;
0046 case 4
0047   idx = m<=elt;
0048 end
0049 f = flatten(m(idx));

Generated on Fri 01-Aug-2014 12:03:17 by m2html © 2005