Skip to content

sort

Sort an array.

v = sort(arr, sort_index, sort_order, by_col)

Sorts the rows or columns of arr. sort_index selects which row/column to sort by (default 1). sort_order is 1 (ascending, default) or -1 (descending). by_col: false (default, sort rows) or true (sort columns).

sort([3 1 4 1 5 9 2 6]) % [1 1 2 3 4 5 6 9]
sort(T, 2, -1) % sort table T by col 2 descending
  • sortby — Sort an array by one or more reference arrays.
  • sortrows — Sort rows of a matrix or table by column values.