MATLAB: Integrating Indices

indexingMATLABmatrix array

Hello,
I have taken the matrix below and sorted it ascending by row:
(Original) A=[1 4 5; 3 -1 8; 12 7 9; 4 10 -5];
(Sorted By Row) B=[1 4 5; -1 3 8; 7 9 12; -5 4 10];
I would like to have the indices of the original matrix appear in the locations of the sorted matrix. For this case it would look like this.
(Original) A=[1 2 3; 1 2 3; 1 2 3; 1 2 3];
(Sorted By Row) B=[1 2 3; 2 1 3; 2 3 1; 3 1 2];
I have tried several different methods but with no luck. Any assistance is appreciated
Thanks

Best Answer

[sorted_A, sort_indexes] = sort(A,2);