Documentation 
Sort input elements by value
The Sort block ranks the values of the input elements using either a quick sort or an insertion sort algorithm. The quick sort algorithm uses a recursive sort method and is faster at sorting more than 32 elements. The insertion sort algorithm uses a nonrecursive method and is faster at sorting less than 32 elements. You should also always use the insertion sort algorithm when you are generating code from the Sort block if you do not want recursive function calls in your code. To specify the sort method, use the Sort algorithm parameter.
The Mode parameter specifies the block's mode of operation, and can be set to Value, Index, or Value and index.
When Mode is set to Value, the block sorts the elements in each column of the MbyN input matrix u in order of ascending or descending value, as specified by the Sort order parameter.
val = sort(u) val = flipud(sort(u))
The output at each sample time, val, is an MbyN matrix containing the sorted columns of u.
The block sorts complex inputs according to their magnitude.
When Mode is set to Index, the block sorts the elements in each column of the MbyN input matrix u,
[val,idx] = sort(u) [val,idx] = flipud(sort(u))
and outputs the MbyN 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)
The index value outputs are always 32bit unsigned integer values.
When Mode is set to Value and index, the block outputs both the sorted matrix, val, and the index matrix, idx.
The parameters on the Data Types pane are only used for complex fixedpoint inputs. Complex fixedpoint inputs are sorted by magnitude squared. The sum of the squares of the real and imaginary parts of such an input are formed before a comparison is made, as described in Value Mode. The results of the squares of the real and imaginary parts are placed into the product output data type. The result of the sum of the squares is placed into the accumulator data type. These parameters are ignored for other types of inputs.
The Main pane of the Sort block dialog appears as follows.
Specify the block's mode of operation: Output the sorted matrix (Value), the index matrix (Index), or both (Value and index).
Specify the order in which to sort the training points, Descending or Ascending.
Specify whether the elements of the input are sorted using a Quick sort or an Insertion sort algorithm.
The Data Types pane of the Sort block dialog appears as follows.
Note The parameters on the Data Types pane are only used for complex fixedpoint inputs. The sum of the squares of the real and imaginary parts of such an input are formed before a comparison is made, as described in Value Mode. The results of the squares of the real and imaginary parts are placed into the product output data type. The result of the sum of the squares is placed into the accumulator data type. These parameters are ignored for other types of inputs. 
Select the rounding mode for fixedpoint operations.
Select the overflow mode for fixedpoint operations.
Specify the product output data type. See FixedPoint Data Types and Multiplication Data Types for illustrations depicting the use of the product output data type in this block. You can set it to:
A rule that inherits a data type, for example, Inherit: Same as input
An expression that evaluates to a valid data type, for example, fixdt([],16,0)
Click the Show data type assistant button to display the Data Type Assistant, which helps you set the Product output data type parameter.
See Specify Data Types Using Data Type Assistant for more information.
Specify the accumulator data type. See FixedPoint Data Types for illustrations depicting the use of the accumulator data type in this block. You can set this parameter to:
A rule that inherits a data type, for example, Inherit: Same as product output
An expression that evaluates to a valid data type, for example, fixdt([],16,0)
Click the Show data type assistant button to display the Data Type Assistant, which helps you set the Accumulator data type parameter.
See Specify Data Types Using Data Type Assistant for more information.
Select this parameter to prevent the fixedpoint tools from overriding the data types you specify on the block mask.
Port  Supported Data Types 

Input 

Val 

Idx 
