Switch output between different inputs based on value of first input
Simulink / Signal Routing
HDL Coder / Signal Routing
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.
Port_1
— Control signalControl 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.
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
0 or 1
— First data inputFirst 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
Port_1
— Selected data input, based on control signal valueThe 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
Data port order
— Type of ordering for data input portsZero-based
contiguous
(default) | One-based contiguous
| Specify indices
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.
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 |
Selecting Zero-based contiguous
or
One-based contiguous
enables the
Number of data ports parameter.
Selecting Specify indices
enables the
Data port indices parameter.
Block Parameter:
DataPortOrder
|
Type: character vector |
Values:
'Zero-based contiguous' | 'One-based contiguous' |
'Specify indices' |
Default:
'Zero-based contiguous' |
Number of data ports
— Number of data input ports1
(default) | integer between 1 and 65536Specify the number of data input ports to the block.
To enable this parameter, set Data port order
to Zero-based contiguous
or
One-based contiguous
.
Block Parameter:
Inputs
|
Type: character vector |
Values: integer between 1 and 65536 |
Default:
'1' |
Require all data port inputs to have the same data type
— Require all inputs to have the same data typeoff
(default) | on
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.
Block Parameter: InputSameDT |
Type: character vector |
Values: 'off' | 'on' |
Default: 'off' |
Output minimum
— Minimum output value for range checking[]
(default) | scalarLower value of the output range that Simulink® checks.
Simulink uses the minimum to perform:
Parameter range checking (see Specify Minimum and Maximum Values for Block Parameters) for some blocks.
Simulation range checking (see Specify Signal Ranges and Enable Simulation Range Checking).
Automatic scaling of fixed-point data types.
Optimization of the code that you generate from the model. This optimization can remove algorithmic code and affect the results of some simulation modes such as SIL or external mode. For more information, see Optimize using the specified minimum and maximum values (Embedded Coder).
Note
Output minimum does not saturate or clip the actual output signal. Use the Saturation block instead.
Block Parameter:
OutMin |
Type: character vector |
Values: '[ ]' |
scalar |
Default: '[ ]' |
Output maximum
— Maximum output value for range checking[]
(default) | scalarUpper value of the output range that Simulink checks.
Simulink uses the maximum value to perform:
Parameter range checking (see Specify Minimum and Maximum Values for Block Parameters) for some blocks.
Simulation range checking (see Specify Signal Ranges and Enable Simulation Range Checking).
Automatic scaling of fixed-point data types.
Optimization of the code that you generate from the model. This optimization can remove algorithmic code and affect the results of some simulation modes such as SIL or external mode. For more information, see Optimize using the specified minimum and maximum values (Embedded Coder).
Note
Output maximum does not saturate or clip the actual output signal. Use the Saturation block instead.
Block Parameter:
OutMax |
Type: character vector |
Values: '[ ]' |
scalar |
Default: '[ ]' |
Output data type
— Specify the output data typeInherit: Inherit via internal
rule
(default) | Inherit: Inherit via back propagation
| 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
| <data type expression>
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.
Block Parameter: OutDataTypeStr |
Type: character vector |
Values: 'Inherit: Inherit via internal
rule | 'Inherit: Inherit via back
propagation' | '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' |
'<data type expression>' |
Default: 'Inherit: Inherit via internal rule' |
Lock output data type setting against changes by the fixed-point tools
— Prevent fixed-point tools from overriding data typesoff
(default) | on
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).
Block Parameter:
LockScale |
Type: character vector |
Values:
'off' |
'on' |
Default:
'off' |
Integer rounding mode
— Specify the rounding mode for fixed-point operationsFloor
(default) | Ceiling
| Convergent
| Nearest
| Round
| Simplest
| Zero
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.
Block Parameter:
RndMeth |
Type: character vector |
Values:
'Ceiling' |
'Convergent' |
'Floor' |
'Nearest' |
'Round' |
'Simplest' |
'Zero' |
Default:
'Floor' |
For more information, see Rounding (Fixed-Point Designer).
Saturate on integer overflow
— Method of overflow actionoff
(default) | on
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.
Block Parameter: SaturateOnIntegerOverflow |
Type: character vector |
Values: 'off' | 'on' |
Default: 'off' |
Allow different data input sizes (Results in variable-size output signal)
— Allow input signals with different sizesoff
(default) | on
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.
Parameter: AllowDiffInputSizes |
Type: character vector |
Value: 'on' | 'off' |
Default: 'off' |
Data Types |
|
Direct Feedthrough |
|
Multidimensional Signals |
|
Variable-Size Signals |
|
Zero-Crossing Detection |
|
HDL Coder™ provides additional configuration options that affect HDL implementation and synthesized logic.
The Index Vector block is a Multiport Switch block with Number of data ports set to 1. For HDL code generation information, see Multiport Switch.