Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Lengths of Continuous Line/Vector
Replies: 4   Last Post: Jun 15, 2014 3:06 AM

 Messages: [ Previous | Next ]
 Roger Stafford Posts: 5,929 Registered: 12/7/04
Re: Lengths of Continuous Line/Vector
Posted: Jan 6, 2013 4:40 PM

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

Date Subject Author
1/6/13 Avri Alony
1/6/13 Roger Stafford
6/14/14 Andrew
6/14/14 dpb
6/15/14 Bruno Luong