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

madhan ravi
madhan ravi 2019년 9월 18일
Please don’t use variable as rank, MATLAB has inbuilt function named rank().
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일

2 개 추천

Possibly:
rank = [4, 1, 2, 2, 4];
[~, ~, rank_new] = unique(rank)

댓글 수: 1

Michal
Michal 2019년 9월 18일
Simple and effective solution ... thanks

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

릴리스

R2019a

질문:

2019년 9월 18일

댓글:

2019년 9월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by