Inverse of sorting arrangement

52 views (last 30 days)
Paolo Binetti
Paolo Binetti on 4 Oct 2018
Commented: Matt J on 28 Jul 2020
[B,I] = sort(A) output is such that B = A(I). What would be the most efficient way to rather get B and J, such that A = B(J)?

Accepted Answer

Stephen
Stephen on 4 Oct 2018
Edited: Stephen on 4 Oct 2018
[B,I] = sort(A);
[~,J] = sort(I);
B(J)

More Answers (1)

Matt J
Matt J on 4 Oct 2018
Edited: Matt J on 4 Oct 2018
[B,I] = sort(A);
J=1:numel(I);
J(I)=J;
  2 Comments
Matt J
Matt J on 28 Jul 2020
Yes, but it can have unintended effects if J is a pre-existing variable in the workspace.

Sign in to comment.

Tags

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!