필터 지우기
필터 지우기

ranking of vector with non-unique elements

조회 수: 1 (최근 30일)
Michal
Michal 2019년 9월 18일
댓글: Michal 2019년 9월 18일
I need to perform fast ranking of the vector with non-unique elements, like in the following example:
F = [10.1 31.0 20.5 20.5 10.1] -> rankF = [3 1 2 2 3]
So far I am using the following code:
[~,~,iFu] = unique(F,'stable');
[~,iFs] = sort(F,'descend');
[~,iFs] = sort(iFs);
[~, ~, rankF] = unique(iFs(iFu));
But, I am not sure if this code is really effective. Is there any better (faster) way how to solve this problem?

채택된 답변

Johannes Fischer
Johannes Fischer 2019년 9월 18일
So you want to order starting with the highest value?
F = [10.1 31.0 20.5 20.5 10.1]
[~, ~, rankF] = unique(max(F)-F)
  댓글 수: 4
Johannes Fischer
Johannes Fischer 2019년 9월 18일
Oh right!
:)
Michal
Michal 2019년 9월 18일
Even better ... thanks Bruno!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Stress and Strain에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by