Issues using index to rank rows of a matrix

조회 수: 1 (최근 30일)
John Harry
John Harry 2020년 5월 6일
댓글: Star Strider 2020년 5월 6일
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
dpb
dpb 2020년 5월 6일
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
Star Strider 2020년 5월 6일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

John Harry
John Harry 2020년 5월 6일
I found the solution to what I needed.
I followed the above with:
[~,index2] = sort(index);
and it returned the ranking I was seeking.
  댓글 수: 4
John Harry
John Harry 2020년 5월 6일
The data is a small excerpt of athlete performance data. The full data set has 30 rows and 20 columns, where each row represents an individual athlete's performance output and each column is a specific task. I wanted to create a new matrix (or single column for the simplified example I used for the inquiry) that maintains the athletes' row but replaces their performance output with the rank of their performance output across all athletes.
Hopefully that helps explain what the purpose is.
John
Star Strider
Star Strider 2020년 5월 6일
That might have helped to respond to the original problem.
Since it’s solved now, it is of historical interest only.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by