Programming |

**Sorting Row Vectors**

The `sortrows`

function keeps the elements of each row in their original order but sorts the entire row vectors according to the order of the elements in the first column:

rowsort = sortrows(A) rowsort = 2.3114 4.5647 7.9194 9.3547 3.5287 6.0684 0.1850 9.2181 9.1690 8.1317 9.5013 7.6210 6.1543 4.0571 0.5789

To run the sort based on a different column, include a second input argument that indicates which column to use. This example sorts the row vectors so that the elements in the third column are in ascending order:

rowsort = sortrows(A, 3) rowsort = 9.5013 7.6210 6.1543 4.0571 0.5789 2.3114 4.5647 7.9194 9.3547 3.5287 6.0684 0.1850 9.2181 9.1690 8.1317 issorted(rowsort(:, 3)) ans = 1

Sorting the Data in Each Row | Operating on Diagonal Matrices |

© 1994-2005 The MathWorks, Inc.