Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Picking Ones among Zeros
Date: Mon, 6 Jul 2009 20:00:18 +0000 (UTC)
Organization: Battelle Energy Alliance (INL)
Lines: 21
Message-ID: <h2tl4i$6jg$1@fred.mathworks.com>
References: <h2oif2$g5h$1@fred.mathworks.com> <h2okru$frv$1@fred.mathworks.com> <h2ti2h$959$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1246910418 6768 172.30.248.38 (6 Jul 2009 20:00:18 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 6 Jul 2009 20:00:18 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 688530
Xref: news.mathworks.com comp.soft-sys.matlab:553200


"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message 
> Matt, Make a test for you and it fails when a = 0 ! Any quick fix?
> 
> Bruno

Bruno at his most diligent :-)....

I = findstr(a,1);
if ~isempty(I)
    I = diff([0 find(diff(I)~=1) length(I)]);
end

Or if we *MUST* keep it to 2 lines:
I = findstr(a,1);
if ~isempty(I), I = diff([0 find(diff(I)~=1) length(I)]);end  % HAHA, still fits...



My turn:

Bruno, your method fails for a = [].  Any quick fix?