Sort
Sort input elements by value.
Description
The Sort block ranks the values of input elements for each channel (column) in ascending or descending order - depending on the value of the Sort order parameter.
Complex input data are sorted by modulus.
With the Sort algorithm parameter you can select the sorting algorithm:
-
Quick sort
- uses recursive sorting method; works faster if more than 32 elements are to be sorted. -
Insertion sort
- uses a non-recursive method; works faster if less than 32 items are to be sorted.
The Mode parameter defines the mode of the block, which you can set to Value
, Index
or Value and Index
.
Ports
Input
Port_1 - data input
vector
| matrix
The block accepts multichannel input data with real or complex value. The input data type must be floating point, integer or fixed point, with derivative equal to the power of two and zero offset.
Data types: Float16
, Float32
, Float64
, Int8
, Int16
, Int32
, Int64
, Int128
, UInt8
, UInt16
, UInt32
, UInt64
, UInt128
.
Support for complex numbers: Yes
Output
Val - sorted data
vector
| matrix
The block sorts the data on each channel and outputs the sorted data through this port. The size, data type, and complexity of the sorted data match the input data. The block sorts complex numbers modulo complex numbers.
Dependencies
To use this port, set the Mode parameter to Value and Index
or Value
.
Data types: Float16
, Float32
, Float64
, Int8
, Int16
, Int32
, Int64
, Int128
, UInt8
, UInt16
, UInt32
, UInt64
, UInt128
.
Support for complex numbers: Yes
Idx - indices of sorted data
vector
| matrix
Indices of sorted data.
Dependencies
To use this port, set the Mode parameter to Value and Index
or ` Index`.
Data types: UInt32
.
Parameters
Main
Mode - specifies whether the block returns values, indexes, or both
Value and Index (by default)
| Value
| Index
When the Mode parameter is set to:
-
Value
- the block sorts the elements in each channel of the input matrix M by N in ascending or descending order, depending on the value of the Sort order parameter. The output data at each sampling moment, , is a matrix M by N that contains sorted columns of the input data.The block sorts complex numbers modulo.
-
Index
- The block sorts the elements in each channel of the input matrix M by N and outputs an array of indices . Each element in represents an integer of typeUInt32
, which indexes the sorted value in the corresponding column of the input data. -
Value and index
- block outputs the sorted values of the input data, , and the corresponding indices in the index array, .
Sort order - sort order
Ascending (by default)
| Descending
Specify whether to sort the input data in ascending or descending order.
Sort algorithm - sorting method
Quick sort (by default)
| Insertion sort
.
The Quick sort
algorithm uses recursive sorting method and works faster if you need to sort more than 32 items. The Insertion sort
algorithm uses a non-recursive method and is faster if you need to sort less than 32 items. When you generate code to avoid recursive function calls, use the Insertion sort
algorithm.