Obtain the sorted index vector
Show older comments
Suppose a vector with element. in Matlab, I can use the following code to sort the vector in descending order as follow:
y=sort(x,'descend'), for example, x=[0.5; 0.4; 0.6; 0.9], then y=[0.9; 0.6; 0.5; 0.4].
I need to Obtain the sorted index vector. Here it will be z=[4; 3; 1; 2]
I need to find z for any arbitrary sorted vector.
Accepted Answer
More Answers (1)
x=[0.5; 0.4; 0.6; 0.9];
y=sort(x,'descend');
[Lia,Locb] = ismember(y,x);
z=Locb'
% if want as a column vector
out=Locb(:)
1 Comment
YAHYA AL-MOLIKI
on 4 Mar 2022
Categories
Find more on Shifting and Sorting Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!