Info
This question is closed. Reopen it to edit or answer.
How to arrange indices of a real array ?
1 view (last 30 days)
Show older comments
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 Comments
Answers (2)
the cyclist
on 21 Nov 2020
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 Comments
the cyclist
on 21 Nov 2020
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
on 21 Nov 2020
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 Comments
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!