Main Content

Index Vector

Switch output between different inputs based on value of first input

  • Index Vector block

Libraries:
Simulink / Signal Routing
HDL Coder / Signal Routing

Description

The Index Vector block is a special configuration of the Multiport Switch block in which you specify one data input and the control input is zero-based. The block output is the element of the input vector whose index matches the control input. For example, if the input vector is [18 15 17 10] and the control input is 3, the element that matches the index of 3 (zero-based) is 10, and that becomes the output value.

To configure a Multiport Switch block to work as an Index Vector block set Number of data ports to 1 and Data port order to Zero-based contiguous.

For more information about the Multiport Switch block, see the Multiport Switch block reference page.

Ports

Input

expand all

Control signal, specified as a scalar. When the control input is not an integer value, the block truncates the value to an integer by rounding to zero.

For information on control signals of enumerated type, see Guidelines on Setting Parameters for Enumerated Control Port on the Multiport Switch block ref page.

Limitations

  • If the control signal is numeric, the control signal cannot be complex.

  • If the control signal is an enumerated signal, the block uses the value of the underlying integer to select a data port.

  • If the underlying integer does not correspond to a data input, an error occurs.

Data Types: single | double | half | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | Boolean | fixed point

First data input, specified as a scalar or vector. The port is labeled 0 when you set Data port order to Zero-based contiguous, and labeled 1 when you set Data port order to One-based contiguous.

Data Types: single | double | half | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | Boolean | fixed point | bus | enumerated | string

Output

expand all

The block outputs the selected value from the input data vector, according to the control signal value. The output is a scalar.

Data Types: single | double | half | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | Boolean | fixed point | enumerated | bus

Parameters

expand all

Main

Specify the type of ordering for your data input ports.

  • Zero-based contiguous — Block uses zero-based indexing for ordering contiguous data ports. This is the default value of the Index Vector block.

  • One-based contiguous — Block uses one-based indexing for ordering contiguous data ports. This is the default value of the Multiport Switch block.

  • Specify indices — Block uses noncontiguous indexing for ordering data ports. This value is supported only for configurations with two or more input data ports.

Tips

  • When the control port is of enumerated type, select Specify indices.

  • If you select Zero-based contiguous or One-based contiguous, verify that the control port is not of enumerated type. This configuration is deprecated and produces an error. You can run the Upgrade Advisor on your model to replace each Multiport Switch block of this configuration with a block that explicitly specifies data port indices. See Model Upgrades.

  • Avoid situations where the block contains unused data ports for simulation or code generation. When the control port is of fixed-point or built-in data type, verify that all data port indices are representable with that type. Otherwise, the following block behavior occurs:

    If the block has unused data ports and data port order is:The block produces:
    Zero-based contiguous or One-based contiguous A warning
    Specify indices An error

Dependencies

Selecting Zero-based contiguous or One-based contiguous enables the Number of data ports parameter.

Selecting Specify indices enables the Data port indices parameter.

Programmatic Use

Block Parameter: DataPortOrder
Type: character vector
Values: 'Zero-based contiguous' | 'One-based contiguous' | 'Specify indices'
Default: 'Zero-based contiguous'

Specify the number of data input ports to the block.

Dependencies

To enable this parameter, set Data port order to Zero-based contiguous or One-based contiguous.

Programmatic Use

Block Parameter: Inputs
Type: character vector
Values: integer between 1 and 65536
Default: '1'

Signal Attributes

Select this check box to require that all data input ports have the same data type. When you clear this check box, the block allows data port inputs to have different data types.

Programmatic Use

Block Parameter: InputSameDT
Type: character vector
Values: 'off' | 'on'
Default: 'off'

Lower value of the output range that Simulink® checks.

Simulink uses the minimum to perform:

Note

Output minimum does not saturate or clip the actual output signal. Use the Saturation block instead.

Programmatic Use

Block Parameter: OutMin
Type: character vector
Values: '[ ]'| scalar
Default: '[ ]'

Upper value of the output range that Simulink checks.

Simulink uses the maximum value to perform:

Note

Output maximum does not saturate or clip the actual output signal. Use the Saturation block instead.

Programmatic Use

Block Parameter: OutMax
Type: character vector
Values: '[ ]'| scalar
Default: '[ ]'

Choose the data type for the output. The type can be inherited, specified directly, or expressed as a data type object such as Simulink.NumericType.

When you select an inherited option, the block behaves as follows:

  • Inherit: Inherit via internal rule—Simulink chooses a data type to balance numerical accuracy, performance, and generated code size, while taking into account the properties of the embedded target hardware. If you change the embedded target settings, the data type selected by the internal rule might change. It is not always possible for the software to optimize code efficiency and numerical accuracy at the same time. If the internal rule doesn’t meet your specific needs for numerical accuracy or performance, use one of the following options:

    • Specify the output data type explicitly.

    • Explicitly specify a default data type such as fixdt(1,32,16) and then use the Fixed-Point Tool to propose data types for your model. For more information, see fxptdlg (Fixed-Point Designer).

    • To specify your own inheritance rule, use Inherit: Inherit via back propagation and then use a Data Type Propagation block. Examples of how to use this block are available in the Signal Attributes library Data Type Propagation Examples block.

  • Inherit: Inherit via back propagation — Uses the data type of the driving block.

  • Inherit: Same as first data input — Uses the data type of the first data input port.

Programmatic Use

Block Parameter: OutDataTypeStr
Type: character vector
Values: 'Inherit: Inherit via internal rule | 'Inherit: Inherit via back propagation' | 'Inherit: Same as first input' | 'double' | 'single' | 'half' | 'int8' | 'uint8' | 'int16' | 'uint16' | 'int32' | 'uint32' | 'int64' | 'uint64' | 'fixdt(1,16)' | 'fixdt(1,16,0)' | 'fixdt(1,16,2^0,0)' | 'string' | Simulink.ImageType(480,640,3) | '<data type expression>'
Default: 'Inherit: Inherit via internal rule'

Select to lock the output data type setting of this block against changes by the Fixed-Point Tool and the Fixed-Point Advisor. For more information, see Use Lock Output Data Type Setting (Fixed-Point Designer).

Programmatic Use

Block Parameter: LockScale
Type: character vector
Values: 'off' | 'on'
Default: 'off'

Choose one of these rounding modes.

Ceiling

Rounds both positive and negative numbers toward positive infinity. Equivalent to the MATLAB® ceil function.

Convergent

Rounds number to the nearest representable value. If a tie occurs, rounds to the nearest even integer. Equivalent to the Fixed-Point Designer™ convergent function.

Floor

Rounds both positive and negative numbers toward negative infinity. Equivalent to the MATLAB floor function.

Nearest

Rounds number to the nearest representable value. If a tie occurs, rounds toward positive infinity. Equivalent to the Fixed-Point Designer nearest function.

Round

Rounds number to the nearest representable value. If a tie occurs, rounds positive numbers toward positive infinity and rounds negative numbers toward negative infinity. Equivalent to the Fixed-Point Designer round function.

Simplest

Automatically chooses between round toward floor and round toward zero to generate rounding code that is as efficient as possible.

Zero

Rounds number toward zero. Equivalent to the MATLAB fix function.

Programmatic Use

Block Parameter: RndMeth
Type: character vector
Values: 'Ceiling' | 'Convergent' | 'Floor' | 'Nearest' | 'Round' | 'Simplest' | 'Zero'
Default: 'Floor'

See Also

For more information, see Rounding (Fixed-Point Designer).

Specify whether overflows saturate or wrap.

  • off — Overflows wrap to the appropriate value that the data type can represent.

    For example, the number 130 does not fit in a signed 8-bit integer and wraps to -126.

  • on — Overflows saturate to either the minimum or maximum value that the data type can represent.

    For example, an overflow associated with a signed 8-bit integer can saturate to -128 or 127.

Tip

  • Consider selecting this check box when your model has a possible overflow and you want explicit saturation protection in the generated code.

  • Consider clearing this check box when you want to optimize efficiency of your generated code.

    Clearing this check box also helps you to avoid overspecifying how a block handles out-of-range signals. For more information, see Troubleshoot Signal Range Errors.

  • When you select this check box, saturation applies to every internal operation on the block, not just the output or result.

  • In general, the code generation process can detect when overflow is not possible. In this case, the code generator does not produce saturation code.

Programmatic Use

Block Parameter: SaturateOnIntegerOverflow
Type: character vector
Values: 'off' | 'on'
Default: 'off'

Select this check box to allow input signals with different sizes.

  • On — Allows input signals with different sizes, and propagate the input signal size to the output signal. In this mode, the block produces a variable-size output signal.

  • Off — Requires that all nonscalar data input signals be the same size.

Programmatic Use

Parameter: AllowDiffInputSizes
Type: character vector
Value: 'on' | 'off'
Default: 'off'

Block Characteristics

Data Types

Boolean | bus | double | enumerated | fixed point | half | integer | single

Direct Feedthrough

yes

Multidimensional Signals

yes

Variable-Size Signals

yes

Zero-Crossing Detection

no

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.

PLC Code Generation
Generate Structured Text code using Simulink® PLC Coder™.

Fixed-Point Conversion
Design and simulate fixed-point systems using Fixed-Point Designer™.

Version History

Introduced before R2006a