Thread Subject: finding list of numbers

Subject: finding list of numbers

From: Jessica

Date: 18 Jun, 2008 02:00:23

Message: 1 of 4

Hi,

Does anyone have any suggestions for finding a clump of
numbers in a column of data?

For example, I have a column:

3
4
5
1
87
6
4
745
0
0
0
0
0
0
5
4
3
5
7
53
2
0
0
0
9
6
5
.
.
.

and I would like to be able to identify both clumps of
zeros by having their start and stop row numbers.
Thus, I would hope to output something that told me that
the first set of zeros is from rows 9-14 and the second set
from 22-24.

Thanks!

Subject: finding list of numbers

From: dpb

Date: 18 Jun, 2008 03:27:37

Message: 2 of 4

Jessica wrote:
...
> and I would like to be able to identify both clumps of
> zeros by having their start and stop row numbers.

As a starting point,

z = find(x==0); % find the locations of zeroes
dz = diff(z) ; % if dz==1, consecutive zeroes

Work back from initial location of where dz==1 occurs to the
corresponding location in z. The first in a sequence will be one less
than the location in dz and the last the last.

--

Subject: finding list of numbers

From: Jessica

Date: 18 Jun, 2008 19:52:02

Message: 3 of 4

dpb <none@non.net> wrote in message
<g39vfm$fnj$1@aioe.org>...
> Jessica wrote:
> ...
> > and I would like to be able to identify both clumps of
> > zeros by having their start and stop row numbers.
>
> As a starting point,
>
> z = find(x==0); % find the locations of zeroes
> dz = diff(z) ; % if dz==1, consecutive zeroes
>
> Work back from initial location of where dz==1 occurs to
the
> corresponding location in z. The first in a sequence
will be one less
> than the location in dz and the last the last.
>
> --

Great suggestion. I got it to work!

Subject: finding list of numbers

From: us

Date: 18 Jun, 2008 20:09:02

Message: 4 of 4

"Jessica ":
<SNIP gap-finder evergreen...

one of the many solutions

% the data
     d=[0,1,2,0,0,3,4,0,6,0];
% the engine
     dd=[true,d~=0,true];
     ixb=strfind(dd,[1,0]);
     ixe=strfind(dd,[0,1])-1;
% the result
     r=[ixb;ixe;ixe-ixb+1]
%{
     1 4 8 10 % start
     1 5 8 10 % end
     1 2 1 1 % #zeros
%}

us

Tags for this Thread

Everyone's Tags:

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.

Tag Activity for This Thread
Tag Applied By Date/Time
code us 18 Jun, 2008 16:10:54
evergreen us 18 Jun, 2008 16:10:54
logical indexing us 18 Jun, 2008 16:10:54
strfind us 18 Jun, 2008 16:10:54
rssFeed for this Thread

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.

Contact us at files@mathworks.com