How to give ranking from highest to lowest
205 次查看(过去 30 天)
显示 更早的评论
Hello, I have number like
Data=[5 6 9 1 5 2]
I want to rank them as: [3 2 1 6 4 5] Can any please help me How can I do this. Thanks in advance.
1 个评论
amrith sg
2022-3-31
i got a average accuracy 79% at rank 1
from rank 2 to rank 10 , i need to find different average accuracy that should be greater than 79%
please give me the code regarding this problem
采纳的回答
Roger Stafford
2014-12-6
This should give you the rank you are asking for, Mekala:
[~,p] = sort(Data,'descend');
r = 1:length(Data);
r(p) = r;
'r' will be the ranking.
1 个评论
Image Analyst
2024-1-27
Data=[5 6 9 1 5 2]
% I want to rank them as: [3 2 1 6 4 5]
[~,p] = sort(Data,'descend');
r = 1:length(Data);
r(p) = r
更多回答(4 个)
Azzi Abdelmalek
2014-12-6
编辑:Azzi Abdelmalek
2014-12-6
Data=[5 6 9 1 5 2]
[sd,r]=sort(Data,'descend')
sd % sorted data
r % the corresponding indices
5 个评论
Azzi Abdelmalek
2014-12-6
We can get the result by sorting the indices resulting from the first sort
Data=[5 6 9 1 5 2]
[~,ii]=sort(Data,'Descend')
[~,r]=sort(ii)
Sandeep Sai Kiran
2021-2-9
编辑:Image Analyst
2024-1-27
Data =[4 8 9 4 7 4]
Kal = sort(Data , 'Descend')
Kapil =sort(Kal)
0 个评论
Zalán Kocsis
2021-6-2
编辑:Image Analyst
2024-1-27
Here's one that assigns the same rank to same values (ties):
Data=[5 6 9 1 5 2];
[C,~,ic] = unique(Data,'sorted'); % ic are ranks from lowest to highest ; C are unique values
r=(1+max(ic)-ic); % r: rank (highest receives 1; lowest receives length(C); tied values receive same rank)
[Data;r']
ASWIN
2024-1-27
编辑:Image Analyst
2024-1-27
A=ones(4);
m=length(A);
r=rank(A)
2 个评论
Dyuman Joshi
2024-1-27
编辑:Dyuman Joshi
2024-1-27
That rank() is different from what OP is asking about.
Image Analyst
2024-1-27
By "ranking" he really meant sorting. Your solution does not give the answer of [3 2 1 6 4 5] that he asked for.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!