Sorting Functions

SMath has the following built-in vector/matrix sorting functions:

  • sort('vector') returns vector with its values sorted in ascending order.
  • rsort('matrix/vector','number') returns matrix/vector with its columns rearranged until the specified row, number, is in ascending order.
  • csort('matrix/vector','number') returns matrix/vector with its rows rearranged until the specified column, number, is in ascending order.
  • reverse('matrix/vector') reverses the order of the rows of a matrix, or of the elements of a vector.

Here is a simple example of using these functions:

sorting example

Note: a 2D plot can be represented as a two-column matrix, where the first column is the x-vector and the second is the y-vector. If you want to sort this matrix before plotting, use eval().

sorting before plotting

This page is based on a legacy wiki article by Radovan Omorjan.