Selector

Select input elements from vector, matrix, or multidimensional signal

Library

Signal Routing

Description

The Selector block generates as output selected or reordered elements of an input vector, matrix, or multidimensional signal.

A Selector block accepts vector, matrix, or multidimensional signals as input. The parameter dialog box and the block's appearance change to reflect the number of dimensions of the input.

Based on the value you enter for the Number of input dimensions parameter, a table of indexing settings is displayed. Each row of the table corresponds to one of the input dimensions in Number of input dimensions. For each dimension, you define the elements of the signal to work with. Specify a vector signal as a 1-D signal and a matrix signal as a 2-D signal. When you configure the Selector block for multidimensional signal operations, the block icon changes.

For example, assume a 6-D signal with a one-based index mode. The table of the Selector block dialog changes to include one row for each dimension. Suppose that you define each dimension with the following entries:

  • Dimension 1

    • Index Option, select Select all

  • Dimension 2

    • Index Option, select Starting index (dialog)

    • Index, enter 2

    • Output Size, enter 5

  • Dimension 3

    • Index Option, select Index vector (dialog)

    • Index, enter [1 3 5]

  • Dimension 4

    • Index Option, select Starting index (port)

    • Output Size, enter 8

  • Dimension 5

    • Index Option, select Index vector (port)

  • Dimension 6

    • Index Option, select Starting and ending indices (port)

The output will be Y=U(1:end,2:6,[1 3 5],Idx4:Idx4+7,Idx5, Idx6(1):Idx6(2)), where Idx4, Idx5, and Idx6 are the index ports for dimensions 4, 5, and 6.

You can use an array of buses as an input signal to a Selector block. For details about defining and using an array of buses, see Combine Buses into an Array of Buses.

Data Type Support

The data port of the Selector block accepts signals of any signal type and any data type that Simulink® supports, including fixed-point and enumerated data types. The data port accepts mixed-type signals. The index port accepts built-in data types, but not Boolean. The elements of the output have the same type as the corresponding selected input elements.

For more information, see Data Types Supported by Simulink in the Simulink documentation.

Parameters and Dialog Box

Number of input dimensions

Enter the number of dimensions of the input signal.

Index mode

Specifies the indexing mode: 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.

Index Option

Define, by dimension, how the elements of the signal are to be indexed. From the list, select:

  • Select all

    No further configuration is required. All elements are selected.

  • Index vector (dialog)

    Enables the Index column. Enter the vector of indices of the elements.

  • Index vector (port)

    No further configuration is required.

  • Starting index (dialog)

    Enables the Index and Output Size columns. Enter the starting index of the range of elements to select in the Index column and the number of elements to select in the Output Size column.

  • Starting index (port)

    Enables the Output Size column. Enter the number of elements to be selected in the Output Size column.

  • Starting and ending indices (port)

    No further configuration is required.

      Note:   Using this option results in a variable-size output signal. When you update the output dimension is set to be the same as the input signal dimension. During execution, the output dimension is updated based on the signal feeding the index.

The Index and Output Size columns appear as needed.

Index

If the Index Option is Index vector (dialog), enter the index of each element in which you are interested.

If the Index Option is Starting index vector (dialog), enter the starting index of the range of elements to be selected.

Output Size

Enter the width (number of elements from the starting point) of the block output signal.

Input port size

Specify the width of the block input signal (-1 for inherited) — 1-D signals only.

Sample time (-1 for inherited)

Specify the time interval between samples. To inherit the sample time, set this parameter to -1. See Specify Sample Time in the online documentation for more information.

    Note:   For 1-D signals, the Sample time parameter is available only when Index Option is Starting index (port), Index vector (port), or Starting and ending indices (port). For all other Index Option settings, the Selector block becomes a virtual block and the Sample time parameter does not appear.

Examples

The sldemo_dblcart1sldemo_dblcart1 model shows the use of three Selector blocks. The following diagram shows what the model looks like after you enable Display > Signals & Ports > Signal Dimensions and simulate the model.

All three Selector blocks set the Index Option to Index vector (dialog), which allows you to specify the indices of the specific signals that you want to select, using the Index parameter. The Input port size parameter is set to the dimension of the largest input signal.

The following model shows the result of simulating two Selector blocks that have the same kind of input signals, but which have two different Index Option settings.

Both Selector blocks select 7 values from the input signal that feeds the U port. However, the Selector block outputs a fixed-size signal, whereas the Selector2 block outputs a variable-size signal whose compiled signal dimension is 10 instead of 7.

The Selector block sets Index Option to Index vector (port), which uses the input signal from Constant1 as the index vector. The dimension of the input signal is 7, so the Display block shows the 7 values of the Constant1 block. The Selector2 block sets the Input port size parameter to 10, which is the size of the largest input signal to the Selector1 block.

The Selector2 block uses the same configuration as the Selector block, except that the Index Option is set to Starting and ending indices (port). The output uses the size of Input port size parameter (10), even though the size of the input signal is 7. The Display2 block shows empty boxes for the three extra dimensions.

Characteristics

Sample Time

Specified in the Sample time parameter

Dimensionalized

Yes

Multidimensionalized

Yes

Virtual

Yes, when Number of input dimensions is 1 and Index Option is Select all, Index vector (dialog), or Starting index (dialog)

For more information, see Virtual Blocks in the Simulink documentation.

Zero-Crossing Detection

No

Was this topic helpful?