0001 function [startIndex stopIndex] = findStartStop(ind, thresh)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
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
0061
0062 return;