Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Lengths of Continuous Line/Vector
Date: Sun, 6 Jan 2013 21:40:08 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 12
Message-ID: <kccqvo$etb$1@newscl01ah.mathworks.com>
References: <5f1a24c9-122c-4cf7-9ab4-d816839abc2c@googlegroups.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-01-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1357508408 15275 172.30.248.46 (6 Jan 2013 21:40:08 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 6 Jan 2013 21:40:08 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:786032

max plank <avrialony@gmail.com> wrote in message <5f1a24c9-122c-4cf7-9ab4-d816839abc2c@googlegroups.com>...
> Let us define vector y = [0 0 0 1 1 1 1 0 0 0 1 1 0]
> I would like to extract the length of the continuous line
> (i.e: ones = [4,2], zeros = [3,3,1])
- - - - - - - - - - 
 d = diff([0,find(diff(x)~=0),length(x)]);
 Zeros = d((x(1)>0)+1:2:end);
 Ones =  d((x(1)<1)+1:2:end);

Note: You should avoid naming any variables 'ones' or 'zeros' (all lowercase) since those are names of matlab built-in functions.

Roger Stafford