Simulink Reference    
Selector

Select input elements from a vector or matrix signal

Library

Signal Routing

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.

Input Type
The type of the input signal: vector or matrix.
Source of element indices
The source of the indices specifying the elements to select, either internal, i.e., the Elements parameter, or external, i.e., an input signal.
Elements
The elements to be included in the output vector.
Input port width
The number of elements in the input vector.

The dialog box appears as follows when matrix input mode is selected.

Input Type
The type of the input signal: vector or matrix.
Source of row indices
The source of the indices specifying the rows to select from the input matrix, either internal, i.e., the Rows parameter, or external, i.e., an input signal.
Rows
Indices of the rows from which to select elements to be included in the output matrix.
Source of column indices
The source of the indices specifying the columns to select from the input matrix, either internal, i.e., the Columns parameter, or external, i.e., an input signal.
Columns
Indices of the columns from which to select elements to be included in the output matrix.

Characteristics

Sample Time
Inherited from driving block
Dimensionalized
Yes


  Scope, Floating Scope S-Function