Main Content

Index Vector

Switch output between different inputs based on value of first input

  • Library:
  • Simulink / Signal Routing

    HDL Coder / Signal Routing

  • Index Vector block

Description

TheIndex Vectorblock is a special configuration of theMultiport Switchblock 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 is3, the element that matches the index of 3 (zero-based) is 10, and that becomes the output value.

To configure aMultiport Switchblock to work as anIndex Vectorblock setNumber of data portsto1andData port ordertoZero-based contiguous.

For more information about the Multiport Switch block, see theMultiport Switchblock 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, seeGuidelines on Setting Parameters for Enumerated Control Porton theMultiport Switchblock 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 labeled0when you setData port ordertoZero-based contiguous, and labeled1when you setData port ordertoOne-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 theIndex Vectorblock.

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

  • 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, selectSpecify indices.

  • If you selectZero-based contiguousorOne-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 eachMultiport Switchblock of this configuration with a block that explicitly specifies data port indices. SeeModel 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 contiguousorOne-based contiguous A warning
    Specify indices An error

Dependencies

SelectingZero-based contiguousorOne-based contiguousenables theNumber of data portsparameter.

SelectingSpecify indicesenables theData port indicesparameter.

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, setData port ordertoZero-based contiguousorOne-based contiguous.

Programmatic Use

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

Signal Attributes

选中此复选框后,要求所有的数据输入ut 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 minimumdoes not saturate or clip the actual output signal. Use theSaturationblock 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 maximumdoes not saturate or clip the actual output signal. Use theSaturationblock 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 asSimulink.NumericType.

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

  • 继承: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 asfixdt(1,32,16)and then use the Fixed-Point Tool to propose data types for your model. For more information, seefxptdlg(Fixed-Point Designer).

    • To specify your own inheritance rule, use继承:Inherit via back propagationand then use aData Type Propagationblock. Examples of how to use this block are available in the Signal Attributes libraryData Type Propagation Examplesblock.

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

  • 继承: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)|''
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, seeUse 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®ceilfunction.

Convergent

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

Floor

Rounds both positive and negative numbers toward negative infinity. Equivalent to the MATLABfloorfunction.

Nearest

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

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 Designerroundfunction.

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 MATLABfixfunction.

Programmatic Use

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

See Also

For more information, seeRounding(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, seeTroubleshoot 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