Issues using index to rank rows of a matrix
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
John Harry
am 6 Mai 2020
Kommentiert: Star Strider
am 6 Mai 2020
Hello,
I have the following simple array:
data = [5.35;4.99;4.77;5.13;3.84];
I am trying to use the sort or sortrows function to provide an index or ranking of the rows, such that row 1 would be assigned a '1', row 2 a '3', row 3 a '4', row 4 a '2', and row 5 a '5'.
I am using the following code:
[~,index] = sortrows(data,'descend');
This returns the following ranking, which is incorrect: 1, 4, 2, 3, 5
Is there a solution to get the index output to return the ranking I am seeking?
Thanks,
John
2 Kommentare
dpb
am 6 Mai 2020
Well, what's the logic behind assigning those indices? They're not based on sorting the input array by value, either ascending nor descending, but some other seemingly more-or-less arbitrary rule.
Can only code what can define first...
Star Strider
am 6 Mai 2020
What criteria are you using to get that ranking? Perhaps I’m missing something, however I don’t see any underlying pattern that would suggest the ranking you want.
Akzeptierte Antwort
John Harry
am 6 Mai 2020
4 Kommentare
Star Strider
am 6 Mai 2020
That might have helped to respond to the original problem.
Since it’s solved now, it is of historical interest only.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!