| 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's appearance 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 specified by element indices. The meaning of the indices depends on the setting of the Index mode parameter. If the setting is One-based (the default), the index of the first input element is 1, the second 2, and so on. If the setting is Zero-based, the index of the first element is 0, the second element 1, and so on.
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 or a range of elements is being selected. For example, this model shows the Selector block 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 is large enough, it displays the ordering of input vector elements graphically.
If Use index as starting value is checked, Elements must specify the starting index of a range of elements that starts at the specified index and whose length is specified by Output port dimensions. For example, suppose that you want the block to select elements 2 through 4 from a six-element input vector. You could do this by selecting the Use index as starting value option, setting the Output port dimensions to 3, and setting Elements to 2.
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 or you select the Use index as starting value option) of one-based or zero-based indices, depending on the setting of the Index mode parameter.
For example, if the Index mode is One-based (the default), 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 data port of the Selector block accepts signals of any signal type and any data type supported by Simulink, including fixed-point data types. The data port accepts mixed-type signal vectors. The index port accepts only builtin data types. The elements of the output vector have the same type as the corresponding selected input elements.
For a discussion on the data types supported by Simulink, refer to Data Types Supported by Simulink in the Using Simulink documentation.
Parameters and Dialog Box
The parameter dialog box appears as follows when you select vector input mode.
vector or matrix.
One-based or Zero-based. If One-based is selected, an index of 1 specifies the first element of the input vector, 2, the second element, and so on. If Zero-based is selected, an index of 0 specifies the first element of the input vector, 1, the second element, and so on.
internal, i.e., the Elements parameter, or external, i.e., an input signal.
Elements field or the external index source is the starting index of a range of elements whose length is the same as the length specified in the Output port dimensions field (see next option).
The dialog box appears as follows when you select matrix input mode.
vector or matrix.
One-based or Zero-based. If One-based is selected, an index of 1 specifies the first row (or column) of the input matrix, 2, the second row, and so on. If Zero-based is selected, an index of 0 specifies the first row (or column) of the input matrix, 0, the second row, and so on.
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.
Row and Column fields or external index sources specify the starting row and column indexes of a range of elements whose length is the same as the dimensions specified in the Output port dimensions field (see next option).
[R C].
Characteristics
| Sample Time |
Inherited from driving block |
| Dimensionalized |
Yes |
| Scope, Floating Scope, Signal Viewer Scope | S-Function | ![]() |
© 1994-2005 The MathWorks, Inc.