Updating numbers to be in sequential order

I have a column of numbers [1 1 2 2 3 1 2 3 3 4 1 1 2] and I want to change the numbers so that they are in sequential order, resulting in [1 1 2 2 3 4 5 6 6 7 8 8 9]. How can I do this?

Answers (2)

sort()

3 Comments

Perhaps I could have phrased my question topic better, but I do not think this method would solve my problem.
Suppose the vector is stored in t. Then
Ordered = cumsum([1; diff(t(:))~=0]);
@Andrew: can you please explain how Walter Roberson's solution does not "solve my problem". Please tell us what you want it to do, or how it should be different.
What exactly is the problem then?

Sign in to comment.

a = [1 1 2 2 3 1 2 3 3 4 1 1 2];
z = [0 3 7];
out = z(cumsum(diff([0,a == 1]) == 1)) + a;

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Asked:

on 22 May 2015

Commented:

on 22 May 2015

Community Treasure Hunt

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

Start Hunting!