필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

How to arrange indices of a real array ?

조회 수: 1 (최근 30일)
Rahim Rahim
Rahim Rahim 2020년 11월 20일
마감: MATLAB Answer Bot 2021년 8월 20일
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

답변 (2개)

the cyclist
the cyclist 2020년 11월 21일
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
the cyclist
the cyclist 2020년 11월 21일
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 2020년 11월 21일
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 2020년 11월 21일
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

이 질문은 마감되었습니다.

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by