Home > reduc > flagEndpoints.m

flagEndpoints

PURPOSE ^

%%%%%%%%%%%%%%%%%%%

SYNOPSIS ^

function indices=flagEndpoints(flags)

DESCRIPTION ^

%%%%%%%%%%%%%%%%%%%

 Given a logical array, find the indices of
 the starts and ends of cunks of ones.

%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function indices=flagEndpoints(flags)
0002 %%%%%%%%%%%%%%%%%%%%
0003 %
0004 % Given a logical array, find the indices of
0005 % the starts and ends of cunks of ones.
0006 %
0007 %%%%%%%%%%%%%%%%%%%%
0008 n=length(flags);
0009 f=reshape(flags,1,n);
0010 delta=f(1,2:n)-f(1,1:n-1);
0011 up=find(delta==1);
0012 down=find(delta==-1);
0013 
0014 %Handle edge effects if the first or last
0015 %flag indicates a noise event.
0016 if (f(1)==1)
0017     up = [0 up];
0018 end
0019 up=up+1;
0020 if (f(n)==1)
0021     down=[down n];
0022 end
0023 
0024 indices=transpose([up;down]);
0025 end

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