Home > reduc > support > findStartStop.m

findStartStop

PURPOSE ^

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

SYNOPSIS ^

function [startIndex stopIndex] = findStartStop(ind, thresh)

DESCRIPTION ^

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

  function [startIndex stopIndex] = findStartStop(ind, thresh)

  function to find the start and stop indices of the events in ind
     
    thresh checks for separation between end of previous event and start of
    next.  

  sjcm
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [startIndex stopIndex] = findStartStop(ind, thresh)
0002 
0003 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0004 %
0005 %  function [startIndex stopIndex] = findStartStop(ind, thresh)
0006 %
0007 %  function to find the start and stop indices of the events in ind
0008 %
0009 %    thresh checks for separation between end of previous event and start of
0010 %    next.
0011 %
0012 %  sjcm
0013 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0014 
0015 stopIndex =[];
0016 startIndex = [];
0017 f1 = 1;
0018 index = 1;
0019 dataLength = length(ind);
0020 while(~isempty(f1))
0021   f1 = find(ind(1:dataLength)==1,1);
0022   f2 = find(ind(f1:dataLength)==0,1)+f1-2;
0023   
0024   if(~isempty(f1))
0025     startIndex(index) = f1;
0026     if(isempty(f2))
0027       f2 = dataLength;
0028     end
0029     stopIndex(index) = f2;
0030     ind(f1:f2) = 0;
0031     index = index+1;
0032   end
0033 end
0034 
0035 if(nargin<2)
0036   return;
0037 end
0038 
0039 if(isempty(startIndex) & isempty(stopIndex))
0040   return;
0041 end
0042 
0043 
0044 newStart(1) = startIndex(1);
0045 newStop(1) = stopIndex(1);
0046 newIndex = 1;
0047 for m=2:length(startIndex)
0048   if(startIndex(m) - newStop(newIndex) < thresh)
0049     newStop(newIndex) = stopIndex(m);
0050   else
0051     newStart(newIndex+1) = startIndex(m);
0052     newStop(newIndex+1) = stopIndex(m);
0053     newIndex = newIndex+1;
0054   end
0055 end
0056 
0057 startIndex = newStart;
0058 stopIndex  = newStop;
0059 
0060 % that's it.
0061 
0062 return;

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