ranking the data in matrix and arrange them as per rank.

5 ビュー (過去 30 日間)
Karanvir singh Sohal
Karanvir singh Sohal 2021 年 4 月 4 日
コメント済み: Bruno Luong 2021 年 4 月 4 日
Hello!
I have a matrix D and E
D=[1 2 3; 7 8 9; 4 5 6; 3 0 5];
E=[D sum(D')' ranks(sum(D')')]
output of E is
E = [ 1 2 3 6 1
7 8 9 24 4
4 5 6 15 3
3 0 5 8 2]
Ok now I have 2 doubts
  1. I want to rank(last column of E) in a way that highest(24) value in column 4 gets rank 1.
  2. I want sort the data in another matrix such that rank 1 row gets on top.
expected results
[7 8 9 24 1
4 5 6 15 2
3 0 5 8 3
1 2 3 6 4]

採用された回答

Bruno Luong
Bruno Luong 2021 年 4 月 4 日
>> D=[1 2 3; 7 8 9; 4 5 6; 3 0 5];
E=[D sum(D')' ranks(sum(D')')]
Unrecognized function or variable 'ranks'.
Did you mean:
>> E=[D sum(D')']
E =
1 2 3 6
7 8 9 24
4 5 6 15
3 0 5 8
>> sortrows(E,-4)
ans =
7 8 9 24
4 5 6 15
3 0 5 8
1 2 3 6
I let youu deal with the last column, that is nothing more or less interesting than the row index of the array
  2 件のコメント
Karanvir singh Sohal
Karanvir singh Sohal 2021 年 4 月 4 日
Great it works as per my requirement for sorting rows.
Can you please tell how to rank? Like row with highest sum will have rank 1.
[25 1
15 2
8 3
6 4]
Bruno Luong
Bruno Luong 2021 年 4 月 4 日
as I said rank after sorting is
r = (1:size(D,1))'
It's a row index of your sorted array.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by