MATLAB: Sort a matrix with indexing

findindexingsort

A row matrix B=[21 43 23 65]. Now I want to sort them in ascending order and also want the order of their location. How to do this??? I want the output file look like: [21 23 43 65] and [1 3 2 4].

Best Answer

[sorted, order] = sort(B)