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: Count numbers considering all cosecutive as one
Replies: 1   Last Post: Jan 20, 2013 2:58 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Bruno Luong

Posts: 8,727
Registered: 7/26/08
Re: Count numbers considering all cosecutive as one
Posted: Jan 20, 2013 2:58 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Mohammad " <badal_204@yahoo.com> wrote in message <kdhek7$4k0$1@newscl01ah.mathworks.com>...
> Hi, I need to count some numbers like:
> Data=2, 3, 4, 7,8 9, 10, 20,25,27;
> 2,3,4=1;
> 7,8,9,10=1;
> 20=1; 25=1; 27=1;
> total count=5 (1+1+1+1+1)
> i.e. consecutive numbers should be count as one together and any individual value should be one.


Data=[2, 3, 4, 7,8 9, 10, 20,25,27]
t = 1 + sum(diff(Data)>1)

% Bruno



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.