How to Sort a Vector With the Same Order As Other Vector in Matlab

Example :
A = [5 3 4 1 2];
B = [-6 -8 -7 -10 -5];
Answer :
C = sortrows([A.' B.']);
or
[A, idx] = sort(A);
B = B(idx);

No comments:

Post a Comment