Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

How to arrange indices of a real array ?

1 Ansicht (letzte 30 Tage)
Rahim Rahim
Rahim Rahim am 20 Nov. 2020
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
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

Antworten (2)

the cyclist
the cyclist am 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 Kommentare
the cyclist
the cyclist am 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.
Rahim Rahim
Rahim Rahim am 21 Nov. 2020
I understand you buddy and thank you for your anwser;
but I want to sort the results of the :
0.7667 0.6516 0.6229 0.5986 0.5897 0.4887 0.2036 0.0997
I mean I want the results be:
7.0000 2.0000 1.0000 5.0000 6.0000 8.0000 3.0000 4.0000
Do you understand me ?

the cyclist
the cyclist am 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

Produkte


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by