User`s guide
Sort
5-407
5Sort
Purpose Sort the elements in the input by value.
Library Statistics
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.