Find a series of consecutive numbers in a vector

Hello, I have a small problem I am trying to solve on Matlab, but....
I have a vector containing timestamps: [1 2 3 6 7 9 10 50 60]
For the consecutive numbers, I only need the first one,so in my example, the answer will be [1 6 9 50 60]
Right now I cannot find a simple way to get that result.
If anyone can help, it would be greatly appreciated.
Thank you!

 Accepted Answer

v = [1 2 3 6 7 9 10 50 60];
x = v([true,diff(v)~=1]);

More Answers (0)

Categories

Find more on Mathematics in Help Center and File Exchange

Asked:

on 20 Feb 2014

Commented:

on 20 Feb 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!