vector of integers modification

1 view (last 30 days)
I have vector of positive integers which I need to modify into vector of consecutive integers with the same ordering.
Example:
rank = [4 1 2 2 4] -> rank_new = [3 1 2 2 3]
  3 Comments
Michal Kvasnicka
Michal Kvasnicka on 18 Sep 2019
Of course, you are right! I just use rank variable name by my mistake... :)

Sign in to comment.

Accepted Answer

Guillaume
Guillaume on 18 Sep 2019
Possibly:
rank = [4, 1, 2, 2, 4];
[~, ~, rank_new] = unique(rank)
  1 Comment
Michal Kvasnicka
Michal Kvasnicka on 18 Sep 2019
Simple and effective solution ... thanks

Sign in to comment.

More Answers (0)

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by