Simulink Reference | ![]() ![]() |
Select input elements from a vector or matrix signal
Library
Description
The Selector block generates as output selected elements of an input vector or matrix.
A Selector block accepts either vector or matrix signals as input. Set the Input Type parameter to the type of signal (vector
or matrix
) that the block should accept in your model. The parameter dialog box and the block icon change to reflect the type of input that you select. The way the block determines the elements to select differs slightly, depending on the type of input.
Vector Input
If the input type is vector, a Selector block outputs a vector of selected elements. The block determines the indices of the elements to select either from the block's Elements parameter or from an external signal. Set the Source of element indices parameter to the source (internal
, i.e., parameter value, or external
) that you prefer. If you select external,
the block adds an input port for the external index signal.
In either case, the elements to be selected must be specified as a vector unless only one element is being selected. For example, this model shows the Selector block icon and the output for an input vector of [2 4 6 8 10]
and an Elements parameter value of [5 1 3]
.
If the block icon is large enough, it displays the ordering of input vector elements graphically.
If you select external
as the source for element indices, the block adds an input port for the element indices signal. The signal should specify the elements to be selected in the same way they are specified, using the Elements parameter.
If the input type is vector, you must specify the width of the input signal or -1, using the Input port width parameter. If you specify a width greater than 0, the width of the input signal must equal the specified width. Otherwise, the block reports an error. If you specify a width of -1, the block accepts a vector signal of any width.
Matrix Input
If the input type is matrix, the Selector block outputs a matrix of elements selected from the input matrix. The block determines the row and column indices of the elements to select either from its Rows and Columns parameters or from external signals. Set the block's Source of row indices and Source of column indices to the source that you prefer (internal
or external
). If you set either source to external
, the block adds an input port for the external indices signal. If you set both sources to external
, the block adds two input ports.
In either case, the indices of the row and columns to be selected must be specified as vectors (or a scalar if only one row or column is to be selected). For example, the Rows expression [2 1]
and the Columns expression [1 3]
specify output of a 2-by-2
matrix whose first row contains the first and third elements of the input matrix's second row and whose second row contains the first and third elements of the input matrix's first row.
Data Type Support
The Selector block accepts signals of any signal and data type, including fixed-point data types. The Selector block supports mixed-type signal vectors. The elements of the output vector have the same type as the corresponding selected input elements.
Parameters and Dialog Box
The parameter dialog box appears as follows when vector input mode is selected.
vector
or matrix
.internal
, i.e., the Elements parameter, or external
, i.e., an input signal.The dialog box appears as follows when matrix input mode is selected.
vector
or matrix
.internal
, i.e., the Rows parameter, or external,
i.e., an input signal.internal
, i.e., the Columns parameter, or external,
i.e., an input signal.Characteristics
Sample Time |
Inherited from driving block |
Dimensionalized |
Yes |
![]() | Scope, Floating Scope | S-Function | ![]() |