Effacer les filtres
Effacer les filtres

How to give ranking from highest to lowest

200 vues (au cours des 30 derniers jours)
Mekala balaji
Mekala balaji le 6 Déc 2014
Commenté : Image Analyst le 27 Jan 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 commentaire
amrith sg
amrith sg le 31 Mar 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

Connectez-vous pour commenter.

Réponse acceptée

Roger Stafford
Roger Stafford le 6 Déc 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 commentaire
Image Analyst
Image Analyst le 27 Jan 2024
Data=[5 6 9 1 5 2]
Data = 1×6
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
r = 1×6
3 2 1 6 4 5

Connectez-vous pour commenter.

Plus de réponses (4)

Azzi Abdelmalek
Azzi Abdelmalek le 6 Déc 2014
Modifié(e) : Azzi Abdelmalek le 6 Déc 2014
Data=[5 6 9 1 5 2]
[sd,r]=sort(Data,'descend')
sd % sorted data
r % the corresponding indices
  5 commentaires
Azzi Abdelmalek
Azzi Abdelmalek le 6 Déc 2014
Ok Roger, I understand now.
Azzi Abdelmalek
Azzi Abdelmalek le 6 Déc 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)

Connectez-vous pour commenter.


Sandeep Sai Kiran
Sandeep Sai Kiran le 9 Fév 2021
Modifié(e) : Image Analyst le 27 Jan 2024
Data =[4 8 9 4 7 4]
Data = 1×6
4 8 9 4 7 4
Kal = sort(Data , 'Descend')
Kal = 1×6
9 8 7 4 4 4
Kapil =sort(Kal)
Kapil = 1×6
4 4 4 7 8 9

Zalán Kocsis
Zalán Kocsis le 2 Juin 2021
Modifié(e) : Image Analyst le 27 Jan 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']
ans = 2×6
5 6 9 1 5 2 3 2 1 5 3 4

ASWIN
ASWIN le 27 Jan 2024
Modifié(e) : Image Analyst le 27 Jan 2024
A=ones(4);
m=length(A);
r=rank(A)
r = 1
  2 commentaires
Dyuman Joshi
Dyuman Joshi le 27 Jan 2024
Modifié(e) : Dyuman Joshi le 27 Jan 2024
That rank() is different from what OP is asking about.
Image Analyst
Image Analyst le 27 Jan 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.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by