Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » Software » comp.soft-sys.matlab

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Roger Stafford

Posts: 5,886
Registered: 12/7/04
Re: Lengths of Continuous Line/Vector
Posted: Jan 6, 2013 4:40 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.