MATLAB: Inverse of sorting arrangement

MATLABsort

[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)?

Best Answer

[B,I] = sort(A);
[~,J] = sort(I);
B(J)