WOLFRAM SYSTEM MODELER
sortSort the rows or columns of a matrix in ascending or descending order |
SystemModel["Modelica.Math.Matrices.sort"]
This information is part of the Modelica Standard Library maintained by the Modelica Association.
sorted_M = Matrices.sort(M); (sorted_M, indices) = Matrices.sort(M, sortRows=true, ascending=true);
Function sort(..) sorts the rows of a Real matrix M in ascending order and returns the result in sorted_M. If the optional argument "sortRows" is false, the columns of the matrix are sorted. If the optional argument "ascending" is false, the rows or columns are sorted in descending order. In the optional second output argument, the indices of the sorted rows or columns with respect to the original matrix are given, such that
sorted_M = if sortedRow then M[indices,:] else M[:,indices];
(M2, i2) := Matrices.sort([2, 1, 0; 2, 0, -1]); -> M2 = [2, 0, -1; 2, 1, 0 ]; i2 = {2,1};
M |
Type: Real[:,:] Description: Matrix to be sorted |
---|---|
sortRows |
Default Value: true Type: Boolean Description: = true, if rows are sorted, otherwise columns |
ascending |
Default Value: true Type: Boolean Description: = true, if ascending order, otherwise descending order |
sorted_M |
Default Value: M Type: Real[size(M, 1),size(M, 2)] Description: Sorted matrix |
---|---|
indices |
Type: Integer[if sortRows then size(M, 1) else size(M, 2)] Description: sorted_M = if sortRows then M[indices,:] else M[:,indices] |