ranking of vector with non-unique elements

2 次查看(过去 30 天)
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 个评论

请先登录,再进行评论。

更多回答(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