|
"D " <dale.kim@gatech.edu> wrote in message <hvbjmg$303$1@fred.mathworks.com>...
> Hello,
>
> I have a huge single column set of data, and within this are intervals of zero's, with each interval a different length.
>
> I used find(A==0) , and it returns a vector of the locations of all zero's. I am ultimately interested in finding the starting and stopping indices of the longest sized interval of zero's.
>
> Can anyone provide tips on how to approach this?
>
> Thank you!
- - - - - - - - -
You can also do it this way. Let d be the column vector of data.
t = diff([false;d==0;false]);
p = find(t==1);
q = find(t==-1);
[maxlen,ix] = max(q-p);
first = p(ix);
last = q(ix)-1;
maxlen is the length of the longest consecutive series of zeros, first is the index of its beginning, and last is the index of its end.
Roger Stafford
|