MATLAB Answers

Inverse of sorting arrangement

30 views (last 30 days)
[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)?

  0 Comments

Sign in to comment.

Accepted Answer

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

  0 Comments

Sign in to comment.

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;

  0 Comments

Sign in to comment.

Sign in to answer this question.

Tags

Products


Release

R2018a