Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: max duration of zero

Subject: max duration of zero

From: Adam Bright

Date: 29 Apr, 2008 21:32:01

Message: 1 of 4

Hi everyone,

If i have an array and every now and again there is a period
of zeros in my data; what would I write to get the longest
period of zeros that occur in my array?

e.g
a=[1;2;0;4;5;6;7;0;0;0;0;3;4;5;6;7;3;5;5;0;0;0]

maxzero in this case is 4.

any help would be much appreciated.

Subject: max duration of zero

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 29 Apr, 2008 21:56:00

Message: 2 of 4

In article <fv844h$f3a$1@fred.mathworks.com>,
Adam Bright <abc_services_2000@yahoo.co.uk> wrote:

>If i have an array and every now and again there is a period
>of zeros in my data; what would I write to get the longest
>period of zeros that occur in my array?

>e.g
>a=[1;2;0;4;5;6;7;0;0;0;0;3;4;5;6;7;3;5;5;0;0;0]

>maxzero in this case is 4.

maxzero = max(diff(find([a;1]))) - 1
--
  "They called it golf because all the other four letter words
  were taken." -- Walter Hagen

Subject: max duration of zero

From: Roger Stafford

Date: 29 Apr, 2008 22:58:02

Message: 3 of 4

roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in message <fv85hg$344
$1@canopus.cc.umanitoba.ca>...
> maxzero = max(diff(find([a;1]))) - 1
----------
  Better append a 1 in front of 'a' also, Walter. If the sequence starts with its
longest series of '0's at the beginning, you will miss it.

Roger Stafford

Subject: max duration of zero

From: Adam Bright

Date: 30 Apr, 2008 15:55:05

Message: 4 of 4

Thanks very much too both of you.

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid>
wrote in message <fv895q$o8j$1@fred.mathworks.com>...
> roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
message <fv85hg$344
> $1@canopus.cc.umanitoba.ca>...
> > maxzero = max(diff(find([a;1]))) - 1
> ----------
> Better append a 1 in front of 'a' also, Walter. If the
sequence starts with its
> longest series of '0's at the beginning, you will miss it.
>
> Roger Stafford
>

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics