Skip to content

sortby

Sort an array by one or more reference arrays.

v = sortby(arr, by_array1, sort_order1, by_array2, sort_order2, ...)

Sorts arr by the values in by_array1 (and ties broken by by_array2, etc.). Each by_array_n must be the same shape as arr. Each sort_order_n is 1 (asc) or -1 (desc).

sortby([10 20 30 40], [3 1 4 2]) % [20 40 10 30]
  • sort — Sort an array.
  • sortrows — Sort rows of a matrix or table by column values.