Navigation

Operators and Keywords

Function List:

C++ API

: [s, i] = sortrows (A)
: [s, i] = sortrows (A, c)

Sort the rows of the matrix A according to the order of the columns specified in c.

By default (c omitted, or a particular column unspecified in c) an ascending sort order is used. However, if elements of c are negative then the corresponding column is sorted in descending order. If the elements of A are strings then a lexicographical sort is used.

Example: sort by column 2 in descending order, then 3 in ascending order

x = [ 7, 1, 4;
      8, 3, 5;
      9, 3, 6 ];
sortrows (x, [-2, 3])
   ⇒ 8  3  5
      9  3  6
      7  1  4

See also: sort.

Package: octave