Info
この質問は閉じられています。 編集または回答するには再度開いてください。
How to arrange indices of a real array ?
1 回表示 (過去 30 日間)
古いコメントを表示
if I have:
Rankig = [ 0.6229 , 0.6516 , 0.2036 , 0.0997 , 0.5986 , 0.5897 , 0.7667 , 0.4887]
I want to arrange indices from the big to the small, I tried
[B,Indexes] = sort(Rankig,'descend');
When I print [Ranking ; Indexes ], I found:
ans =
0.6229 0.6516 0.2036 0.0997 0.5986 0.5897 0.7667 0.4887
7.0000 2.0000 1.0000 5.0000 6.0000 8.0000 3.0000 4.0000
This method did not work, any help ?
I want the result be:
0.6229 0.6516 0.2036 0.0997 0.5986 0.5897 0.7667 0.4887
6.0000 7.0000 2.0000 1.0000 5.0000 4.0000 8.0000 3.0000
I mean 1 => the small value wich is 0.0997
2 => the second small value
etc ... and 8 => the big value 0.7667
0 件のコメント
回答 (2 件)
the cyclist
2020 年 11 月 21 日
You are just interpreting the output incorrectly.
[B, Indexes]
ans =
0.7667 0.6516 0.6229 0.5986 0.5897 0.4887 0.2036 0.0997
7.0000 2.0000 1.0000 5.0000 6.0000 8.0000 3.0000 4.0000
B is the sorted values.
Interpret the output as "The largest value of Rankig has value 0.7667, and it is the 7th element."
3 件のコメント
the cyclist
2020 年 11 月 21 日
Here is the sorting, in descending order:
- 0.7667, which is the 7th element of Rankig
- 0.6516, which is the 2nd element of Rankig
- 0.6229, which is the 1st element of Rankig
- 0.5986, which is the 5th element of Rankig
- 0.5897, which is the 6th element of Rankig
- 0.4887, which is the 8th element of Rankig
- 0.2036, which is the 3rd element of Rankig
- 0.0997, which is the 4th element of Rankig
B is the values, from largest to smallest.
Indexes is the position in Rankig.
I'm not sure how else to explain it.
the cyclist
2020 年 11 月 21 日
Rankig = [ 0.6229 , 0.6516 , 0.2036 , 0.0997 , 0.5986 , 0.5897 , 0.7667 , 0.4887];
[~,Indexes] = sort(Rankig);
[~,Indexes2] = sort(Indexes);
output = [Rankig; Indexes2]
output =
0.6229 0.6516 0.2036 0.0997 0.5986 0.5897 0.7667 0.4887
6.0000 7.0000 2.0000 1.0000 5.0000 4.0000 8.0000 3.0000
0 件のコメント
この質問は閉じられています。
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!