Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!q40g2000prh.googlegroups.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Picking Ones among Zeros
Date: Mon, 6 Jul 2009 12:59:15 -0700 (PDT)
Organization: http://groups.google.com
Lines: 28
Message-ID: <987ab093-7a3a-4f31-a470-832243bcbce9@q40g2000prh.googlegroups.com>
References: <h2oif2$g5h$1@fred.mathworks.com>
NNTP-Posting-Host: 128.195.202.164
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1246910355 29309 127.0.0.1 (6 Jul 2009 19:59:15 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Mon, 6 Jul 2009 19:59:15 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: q40g2000prh.googlegroups.com; posting-host=128.195.202.164; 
	posting-account=2xaS4woAAABMTlLr8rCm508E1dml7wGx
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; WOW64; 
	Trident/4.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 
	3.0.30618; MAXTHON 2.0),gzip(gfe),gzip(gfe)
Xref: news.mathworks.com comp.soft-sys.matlab:553199


On Jul 4, 2:44 pm, "Frederic Sigoillot" <sigoil...@yahoo.fr> wrote:
> Hello,
>
> What would be the simplest way to retrieve the size of connected components (ones) in a binary string?
>
> as example, I have
>
> a= [ 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 0 0 0 0 0 1 1 0 0 0 0]
>
> I would like to return>>b
>
>       4
>       7
>       2
>
> There are 4 connected 'Ones' then 7 and then 2 among the zeros.
>
> Thank you!
>
> Frederic


Here's another solution:


b = strfind(a,[1 0]) - strfind(a,[0 1])