Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

How to arrange indices of a real array ?

1 visualización (últimos 30 días)
Rahim Rahim
Rahim Rahim el 20 de Nov. de 2020
Cerrada: MATLAB Answer Bot el 20 de Ag. de 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

Respuestas (2)

the cyclist
the cyclist el 21 de Nov. de 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 comentarios
the cyclist
the cyclist el 21 de Nov. de 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 el 21 de Nov. de 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 el 21 de Nov. de 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

Etiquetas

Productos


Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by