How to sort each row of 120x200 array and keep track of column number ?

2 views (last 30 days)
I have 120x200 array , I want to sort each row but I need to keep column number of each entry. so let's sey it is my array :
7 8 2 1
3 9 6 5
5 2 1 9
this should be
1 2 7 8
3 5 6 9
1 2 5 9
and also I need to use old column number of each term ,for example 7 was in column 1 .
How can I do this in matlab (I can do sorting ,but problem is keep track of column numbers)

Accepted Answer

Jos (10584)
Jos (10584) on 16 Dec 2014
Use the second output of SORT:
A = [7 8 2 1 ; 3 9 6 5 ; 5 2 1 9]
[Asorted, OrigColIdx] = sort(A,2)

More Answers (0)

Categories

Find more on Shifting and Sorting Matrices in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!