Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Picking Ones among Zeros
Date: Sat, 4 Jul 2009 21:44:02 +0000 (UTC)
Organization: Harvard Medical School
Lines: 19
Message-ID: <h2oif2$g5h$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1246743842 16561 172.30.248.37 (4 Jul 2009 21:44:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 4 Jul 2009 21:44:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1896560
Xref: news.mathworks.com comp.soft-sys.matlab:552816


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