sort

Sort elements of complex vector

Information

This information is part of the Modelica Standard Library maintained by the Modelica Association.

Syntax

           sorted_v = Vectors.sort(v);
(sorted_v, indices) = Vectors.sort(v, ascending=true);

Description

Function sort(..) sorts a Real vector v in ascending order and returns the result in sorted_v. If the optional argument "ascending" is false, the vector is sorted in descending order. In the optional second output argument the indices of the sorted vector with respect to the original vector are given, such that sorted_v = v[indices].

Example

  (v2, i2) := Vectors.sort({-1, 8, 3, 6, 2});
       -> v2 = {-1, 2, 3, 6, 8}
          i2 = {1, 5, 3, 4, 2}

Syntax

(sorted_v, indices) = sort(v, ascending, sortFrequency)

Inputs (3)

v

Type: Complex[:]

Description: Vector to be sorted

ascending

Default Value: true

Type: Boolean

Description: = true if ascending order, otherwise descending order

sortFrequency

Default Value: true

Type: Boolean

Description: = true, if sorting is first for imaginary then for real value; = false, if sorting is for absolute value

Outputs (2)

sorted_v

Default Value: v

Type: Complex[size(v, 1)]

Description: Sorted vector

indices

Default Value: 1:size(v, 1)

Type: Integer[size(v, 1)]

Description: sorted_v = v[indices]