How to get the max value index and the next max value index and next until the end (the smallest) of the array

조회 수: 1 (최근 30일)
For example if A Vector
A=[5.2,6.3,1.2,10,2,4.3];
I want to get the index of the max value (in my example is 10 so the index is 4) then find the next max value which is 6.3 then the index is 2,,, the final output i need it to be as follows:
I=[3,2,6,1,5,4]
where I the returned indices corresponding to A

채택된 답변

Ibrahim Fares
Ibrahim Fares 2019년 1월 11일
편집: Ibrahim Fares 2019년 1월 11일
I solved this problem, so I will share it with you:
function [ mapped] = mapping( x )
for i = 1:length(x)
[~,j]=max(x);
mapped(j)=i;
x(j)=-inf;
end
end

추가 답변 (1개)

madhan ravi
madhan ravi 2019년 1월 6일
[~,I]=sort(A)
  댓글 수: 3
Ibrahim Fares
Ibrahim Fares 2019년 1월 6일
Thanks for your interest, but A randomly changes in an iteration, is always do this step?
and why this happens?
madhan ravi
madhan ravi 2019년 1월 6일
편집: madhan ravi 2019년 1월 6일
"[D,I] = sort(A) also returns a sort index I which specifies how the
elements of A were rearranged to obtain the sorted output D:"
>> [D,I]=sort(A)
D =
1.2000 2.0000 4.3000 5.2000 6.3000 10.0000
I =
3 5 6 1 2 4 % indices of orginal values
>>

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

카테고리

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