Main Content

Guidelines for Using Selector Blocks to Extract Input Elements from Vector or Matrix Signals

Follow these guidelines when you want to select input elements from vector or matrix signals using Selector blocks.

Each guideline has a severity level that indicates the level of compliance requirements. To learn more, see HDL Modeling Guidelines Severity Levels.

Guideline ID

2.3.3

Severity

Recommended

Description

To extract scalar or partial vector input elements from vector or matrix signals in a model that you want to use for HDL Code generation, use Selector, Multiport Selector (DSP System Toolbox) or Index Vector blocks. Use these parameter settings:

Intended UsageRecommended BlockBlock Parameter SettingsFor Vector InputsFor Matrix Inputs
Extracting one signal from vector or matrix inputs with a fixed or variable output range Selector

Index mode: Zero-based

Index option: Select index options with (dialog) when the output range is fixed. For variable output range, select options with (port).

  • Index vector (dialog): Specify the output range by entering index of each element.

  • Start index (dialog): Select the output range by specifying the start index and output size.

  • Index vector (port): Select the output range by specifying the index in the external port.

  • Start index (port): Select the output range by specifying the index in the external port and a fixed output size.

  • First and last index (port): HDL code generation is not supported for variable size.

Set the Number of input dimensions to 1.

The Selector block output is a:

  • Scalar when you specify only one index

  • Vector when you specify multiple indices

Set the Number of input dimensions to 2.

The Selector output is a:

  • Scalar when you specify only one index for first and second dimension

  • Row vector when you specify the only one index for first dimension

  • Column vector when you specify the only one index for second dimension

  • Matrix when you specify multiple indices for first and second dimension.

Extracting multiple signals from a vector signal with a fixed output rangeMultiport Selector (DSP System Toolbox)

Specify multiple subsets of scalar or vector indices to the Indices to output parameter.

Example: {1, [2,4]}

The block uses one-based indexing.

The block generates output signal for each index set respectively.

Depending on whether each index set is a scalar or a vector, the corresponding output port is also a scalar or vector signal.

HDL code generation is not supported for matrix input.

To extract multiple ranges from a matrix, convert the matrix input signal to a vector.

Extracting only one element as a signal from a vector signal Index Vector

Data port order: Zero-based contiguous

Number of data ports: 1

HDL Block PropertyCoding Style: Set to case_stmt to generate code as a case statement. Do not use the ifelse_stmt setting, because it brings deep logic combination using if-elseif structure.

You can select only one element in the input vector. The block output is a scalar signal.Simulation and HDL code generation are not supported for matrix inputs.

Modeling Considerations

  • Although you can use the Variable Selector block when the extraction range is variable and the inputs and outputs are vectors, the HDL code generated from this block has an if-elseif structure, and is therefore not recommended for this configuration.

  • When you use Selector and Variable Selector blocks that has variable extraction range, you must use a built-in data type such as uint8 as an input to the Index port(Idx). This may cause small redundant circuit.

  • Selector and Multiport Selector blocks support zero-based indices. When you use Selector or Multiport Selector blocks to select multiple elements, vector or matrix signal is output from one port. Though the HDL code generated from a Selector that uses zero-based index and Multiport Selector are the same, the code from Selector block has better traceability because it keeps the same indices between the model and the generated code.

  • Although the MATLAB code only supports one-based indices, the generated HDL code uses zero-based indexes. When you use Selector block to extract multiple sets of elements, these sets are output from multiple output ports in the generated HDL code.

See Also

| (DSP System Toolbox) |