DSP Blockset | ![]() ![]() |
Sort the elements in the input by value.
Library
Description
The Sort block sorts the elements in each column of the input using a Quicksort algorithm. The Mode parameter specifies the block's mode of operation, and can be set to Value, Index, or Value and Index.
Value Mode
When Mode is set to Value, the block sorts the elements in each column of the M-by-N input matrix u
in order of ascending or descending value, as specified by the Sort order parameter.
val = sort(u) % Equivalent MATLAB code (ascending) val = flipud(sort(u)) % Equivalent MATLAB code (descending)
For convenience, length-M 1-D vector inputs and sample-based length-M row vector inputs are both treated as M-by-1 column vectors.
The output at each sample time, val
, is a M-by-N matrix containing the sorted columns of u
. Complex inputs are sorted by magnitude, and the output has the same frame status as the input.
Index Mode
When Mode is set to Index, the block sorts the elements in each column of the M-by-N input matrix u
,
[val,idx] = sort(u) % Equivalent MATLAB code (ascending) [val,idx] = flipud(sort(u)) % Equivalent MATLAB code (descending)
and outputs the sample-based M-by-N index matrix, idx
. The jth column of idx
is an index vector that permutes the jth column of u
to the desired sorting order:
val(:,j) = u(idx(:,j),j)
As in Value mode, length-M 1-D vector inputs and sample-based length-M row vector inputs are both treated as M-by-1 column vectors.
Value and Index Mode
When Mode is set to Value and Index, the block outputs both the sorted matrix, val
, and the index matrix, idx
.
Dialog Box
See Also
Histogram |
DSP Blockset |
Median |
DSP Blockset |
sort |
MATLAB |
![]() | Singular Value Decomposition | Spectrum Scope | ![]() |