vector of integers modification

1 回表示 (過去 30 日間)
Michal
Michal 2019 年 9 月 18 日
コメント済み: Michal 2019 年 9 月 18 日
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 件のコメント
Guillaume
Guillaume 2019 年 9 月 18 日
There are so many functions in matlab that it can be difficult not to shadow one. If you're not doing matrix algebra it doesn't really matter if you stomp on rank.
On the other hand, rank is not a particularly good variable name. rank of what? It would be much better if that what was added to the variable name.
Michal
Michal 2019 年 9 月 18 日
Of course, you are right! I just use rank variable name by my mistake... :)

サインインしてコメントする。

採用された回答

Guillaume
Guillaume 2019 年 9 月 18 日
Possibly:
rank = [4, 1, 2, 2, 4];
[~, ~, rank_new] = unique(rank)
  1 件のコメント
Michal
Michal 2019 年 9 月 18 日
Simple and effective solution ... thanks

サインインしてコメントする。

その他の回答 (0 件)

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by