How to give ranking from highest to lowest
200 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Mekala balaji
el 6 de Dic. de 2014
Comentada: Image Analyst
el 27 de En. de 2024
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 comentario
amrith sg
el 31 de Mzo. de 2022
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
Respuesta aceptada
Roger Stafford
el 6 de Dic. de 2014
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 comentario
Image Analyst
el 27 de En. de 2024
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
Más respuestas (4)
Azzi Abdelmalek
el 6 de Dic. de 2014
Editada: Azzi Abdelmalek
el 6 de Dic. de 2014
Data=[5 6 9 1 5 2]
[sd,r]=sort(Data,'descend')
sd % sorted data
r % the corresponding indices
5 comentarios
Azzi Abdelmalek
el 6 de Dic. de 2014
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
el 9 de Feb. de 2021
Editada: Image Analyst
el 27 de En. de 2024
Data =[4 8 9 4 7 4]
Kal = sort(Data , 'Descend')
Kapil =sort(Kal)
0 comentarios
Zalán Kocsis
el 2 de Jun. de 2021
Editada: Image Analyst
el 27 de En. de 2024
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
el 27 de En. de 2024
Editada: Image Analyst
el 27 de En. de 2024
A=ones(4);
m=length(A);
r=rank(A)
2 comentarios
Dyuman Joshi
el 27 de En. de 2024
Editada: Dyuman Joshi
el 27 de En. de 2024
That rank() is different from what OP is asking about.
Image Analyst
el 27 de En. de 2024
By "ranking" he really meant sorting. Your solution does not give the answer of [3 2 1 6 4 5] that he asked for.
Ver también
Categorías
Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!