http://www.mathworks.com/matlabcentral/newsreader/view_thread/284791
MATLAB Central Newsreader  Finding the longest length of zero's...
Feed for thread: Finding the longest length of zero's...
enus
©19942015 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Wed, 16 Jun 2010 22:37:04 +0000
Finding the longest length of zero's...
http://www.mathworks.com/matlabcentral/newsreader/view_thread/284791#755090
D
Hello,<br>
<br>
I have a huge single column set of data, and within this are intervals of zero's, with each interval a different length.<br>
<br>
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.<br>
<br>
Can anyone provide tips on how to approach this?<br>
<br>
Thank you!

Wed, 16 Jun 2010 22:46:45 +0000
Re: Finding the longest length of zero's...
http://www.mathworks.com/matlabcentral/newsreader/view_thread/284791#755094
ImageAnalyst
Do you have the Image Processing Toolbox? Is so, it's trivial. Just<br>
call bwlabel and regionprops then pull out the biggest object. It<br>
doesn't matter that it's a 1D "image" instead of a 2D image.

Wed, 16 Jun 2010 23:24:22 +0000
Re: Finding the longest length of zero's...
http://www.mathworks.com/matlabcentral/newsreader/view_thread/284791#755106
Matt Fig
ImageAnalyst <imageanalyst@mailinator.com> wrote in message <2b1bac7aa7514341b0252e251f6bbdb7@z25g2000vbk.googlegroups.com>...<br>
> Do you have the Image Processing Toolbox? Is so, it's trivial. Just<br>
> call bwlabel and regionprops then pull out the biggest object. It<br>
> doesn't matter that it's a 1D "image" instead of a 2D image.<br>
<br>
If not, you can use your logical result this way:<br>
<br>
B = A==0;<br>
st = findstr(B.',[0 1])+1; % If A is a column vector. The starting points<br>
ed = findstr(B.',[1 0]); % The ending points.<br>
% Now, assuming you take care of any boundary problems (I leave to you)....<br>
[idx,idx] = max(edst);<br>
idx = st(idx)

Thu, 17 Jun 2010 00:13:03 +0000
Re: Finding the longest length of zero's...
http://www.mathworks.com/matlabcentral/newsreader/view_thread/284791#755116
Roger Stafford
"D " <dale.kim@gatech.edu> wrote in message <hvbjmg$303$1@fred.mathworks.com>...<br>
> Hello,<br>
> <br>
> I have a huge single column set of data, and within this are intervals of zero's, with each interval a different length.<br>
> <br>
> 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.<br>
> <br>
> Can anyone provide tips on how to approach this?<br>
> <br>
> Thank you!<br>
        <br>
You can also do it this way. Let d be the column vector of data.<br>
<br>
t = diff([false;d==0;false]);<br>
p = find(t==1);<br>
q = find(t==1);<br>
[maxlen,ix] = max(qp);<br>
first = p(ix);<br>
last = q(ix)1;<br>
<br>
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.<br>
<br>
Roger Stafford

Thu, 17 Jun 2010 13:48:04 +0000
Re: Finding the longest length of zero's...
http://www.mathworks.com/matlabcentral/newsreader/view_thread/284791#755269
D
"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <hvbpaf$hlf$1@fred.mathworks.com>...<br>
> "D " <dale.kim@gatech.edu> wrote in message <hvbjmg$303$1@fred.mathworks.com>...<br>
> > Hello,<br>
> > <br>
> > I have a huge single column set of data, and within this are intervals of zero's, with each interval a different length.<br>
> > <br>
> > 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.<br>
> > <br>
> > Can anyone provide tips on how to approach this?<br>
> > <br>
> > Thank you!<br>
>         <br>
> You can also do it this way. Let d be the column vector of data.<br>
> <br>
> t = diff([false;d==0;false]);<br>
> p = find(t==1);<br>
> q = find(t==1);<br>
> [maxlen,ix] = max(qp);<br>
> first = p(ix);<br>
> last = q(ix)1;<br>
> <br>
> 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.<br>
> <br>
> Roger Stafford<br>
<br>
<br>
<br>
Thank you all!