MATLAB: Sort Matrix by rows

matrixmatrix arraysort

I have a matrix which first row indicates index numbers and second indicated the data. For example it goes like this:
1 2 3 4 5 6
23 45 10 90 11 34
I want to sort these descending but I don't want to loose the corresponding index either.
4 2 6 1 5 3
90 45 34 23 11 10
I have a large amount of data so it needs to be efficient too. How can I do that?

Best Answer

Hi,
A =
1 2 3 4 5 6
23 45 10 90 11 34
>> A=A'
A =
1 23
2 45
3 10
4 90
5 11
6 34
>> B=sortrows(A,-2)
B =
4 90
2 45
6 34
1 23
5 11
3 10
>> B=B'
B =
4 2 6 1 5 3
90 45 34 23 11 10
Or short:
B=(sortrows(A',-2))'
B =
4 2 6 1 5 3
90 45 34 23 11 10