フィルターのクリア

How to give ranking from highest to lowest

200 ビュー (過去 30 日間)
Mekala balaji
Mekala balaji 2014 年 12 月 6 日
コメント済み: Image Analyst 2024 年 1 月 27 日
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
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
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
Image Analyst 2024 年 1 月 27 日
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

サインインしてコメントする。

その他の回答 (4 件)

Azzi Abdelmalek
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
Azzi Abdelmalek 2014 年 12 月 6 日
Ok Roger, I understand now.
Azzi Abdelmalek
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
Sandeep Sai Kiran 2021 年 2 月 9 日
編集済み: Image Analyst 2024 年 1 月 27 日
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 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']
ans = 2×6
5 6 9 1 5 2 3 2 1 5 3 4
  1 件のコメント
HB
HB 2021 年 10 月 19 日
Thanks!

サインインしてコメントする。


ASWIN
ASWIN 2024 年 1 月 27 日
編集済み: Image Analyst 2024 年 1 月 27 日
A=ones(4);
m=length(A);
r=rank(A)
r = 1
  2 件のコメント
Dyuman Joshi
Dyuman Joshi 2024 年 1 月 27 日
編集済み: Dyuman Joshi 2024 年 1 月 27 日
That rank() is different from what OP is asking about.
Image Analyst
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.

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by