tags:

views:

67

answers:

3

Suppose I have the following array

1.0000    2.0000    0.4231
1.0000    3.0000    0.8050
1.0000    4.0000    0.7116
2.0000    4.0000    0.6682
2.0000    5.0000    0.4460
2.0000    7.0000    0.5818
3.0000    4.0000    0.0977
3.0000    6.0000    0.5989
3.0000    7.0000    0.3237
4.0000    7.0000    0.2882
5.0000    6.0000    0.1456
5.0000    7.0000    0.3168
6.0000    7.0000    0.2767

I want to sort rows according to the elements of column 3 in a descending order. So that the sorted array is like:

1.0000 3.0000 0.8050

1.0000 4.0000 0.7116

2.0000 4.0000 0.6682

3.0000 6.0000 0.5989

.......................................

.......................................

Note that, if I use 'sortrows' then the array is sorted in a ascending order automatically which I could not change. If I use 'sort', each column is sorted individually which is not what I want. Any help would be highly appreciated.

-Faisal

+2  A: 

Read the next page of the manual:

sortrows(X,COL) sorts the matrix based on the columns specified in the vector COL.

especially the next sentence after the one I have quoted.

High Performance Mark
Would vote up except why don't you just post "the next sentence".
Dustin Fineout
@Dustin: because I grew tired of cutting and pasting text from the Matlab on-line help. I'm not proud of it, but it was all the strength I could muster at the time.
High Performance Mark
A: 

sortrows(yourArray,3)

nuriaion
+3  A: 

To sort in descending order you need a negative column index.

sortrows(a, -3)
KennyTM
thank you very much. This solves my problem.
Faisal

related questions