| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Simulink |
| Contents | Index |
| Learn more about Simulink |
Signal Routing

The Multiport Switch block chooses among several inputs. The first input is the control input, while the rest of the inputs are data inputs.
The value of the control input determines which data input passes through to the output port. See How to Rotate a Block in the Simulink documentation for a description of the port order for various block orientations.
You specify the number of data inputs with the Number of inputs parameter. These data inputs can be scalar or vector. The following rules determine the block output:
If you specify only one data input and that input is a vector, the block behaves as an "index selector," and not as a multiport switch. The block output is the vector element that corresponds to the value of the control input.
If you specify more than one data input, the block behaves like a multiport switch. The block output is the data input that corresponds to the value of the control input. If at least one of the data inputs is a vector, the block output is a vector. The block expands any scalar inputs to vectors.
If the data inputs are scalar, the output is a scalar.
The following table summarizes how the block interprets the control input and passes data to the output.
| Control Input | Truncation | Setting for Zero-Based Indexing | Block Behavior During Simulation |
|---|---|---|---|
| Integer value | None | On | The specified data input passes to the output, based on zero-based indexing. If the control input is less than 0 or greater than the number of data inputs minus one, an out-of-range error appears. |
| Off | The specified data input passes to the output, based on one-based indexing. If the control input is less than 1 or greater than the number of data inputs, an out-of-range error appears. | ||
| Not an integer value | The block truncates the value to an integer by rounding to floor. | On | The specified data input passes to the output, based on zero-based indexing. If the truncated control input is less than 0 or greater than the number of data inputs minus one, an out-of-range error appears. |
| Off | The specified data input passes to the output, based on one-based indexing. If the truncated control input is less than 1 or greater than the number of data inputs, an out-of-range error appears. |
The following table summarizes how the block defines the default output for an out-of-range control input.
| Block Usage | How the Block Defines the Default Output |
|---|---|
| Simulation | None, because an out-of-range control input results in an error. |
| Real-Time Workshop generated code | Undefined |
| Accelerator modes | Undefined |
Tip Ensure that you use an in-range control input for the Multiport Switch block. Avoid relying on undefined behavior for Real-Time Workshop generated code or Accelerator modes. |
The Index Vector block, also in the Signal Routing library, is another implementation of the Multiport Switch block that has different default parameter settings.
The control signal can be of any data type that Simulink supports, including fixed-point and enumerated types, except Boolean. If the control signal is numeric, it 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 port, an error occurs.
The data signals can be of any data type that Simulink supports. If any data signal is of an enumerated type, all others must be of the same enumerated type.
For more informaiton, see Data Types Supported by Simulink in the Simulink documentation.
The Main pane of the Multiport Switch block dialog box appears as follows:

The Signal Attributes pane of the Multiport Switch block dialog box appears as follows:

Default: 1
Specify the number of data inputs to the block.
Specify block indexing.
Default: Off
Specify the time interval between samples.
Default: -1
This setting indicates the block inherits the sample time.
Specify allowed data types.
Default: Off
Requires all data port inputs to have the same data type.
Allows data port inputs to have different data types.
Select to lock the output data type setting of this block against changes by the Fixed-Point Tool and the Fixed-Point Advisor.
Default: Off
Locks the output data type setting for this block.
Allows the Fixed-Point Tool and the Fixed-Point Advisor to change the output data type setting for this block.
See Block-Specific Parameters for the command-line information.
For more information, see Fixed-Point Tool and Fixed-Point Advisor in the Simulink Fixed Point documentation.
Select the rounding mode for fixed-point operations.
Default: Floor
Rounds toward positive infinity and is equivalent to the MATLAB ceil function.
Rounds toward the nearest representable number, with ties rounding to the nearest even integer. Convergent rounding is equivalent to the Fixed-Point Toolbox convergent function.
Rounds toward negative infinity and is equivalent to the MATLAB floor function.
Rounds toward the nearest representable number, with the exact midpoint rounded toward positive infinity. Rounding toward nearest is equivalent to the Fixed-Point Toolbox nearest function.
Rounds to the nearest representable number. Ties for positive numbers round in the direction of positive infinity and ties for negative numbers round in the direction of negative infinity. This mode is equivalent to the Fixed-Point Toolbox round function.
Automatically chooses between round toward floor and round toward zero to produce generated code that is as efficient as possible
Rounds toward zero and is equivalent to the MATLAB fix function.
Specify what to do with overflows.
Default: Off
Allows overflows to saturate. Saturation applies to every internal operation on the block, not just the output or result. In general, the code generation process can detect when an overflow is not possible. In this case, the code generator does not produce saturation code.
Does not allow overflow to saturate.
Select this check box to allow input signals with different sizes.
Default: Off
Allows input signals with different sizes, and propagate the input signal size to the output signal.
Requires that input signals be the same size.
| Parameter: AllowDiffInputSignals |
| Type: string |
| Value: 'on' | 'off' |
| Default: 'off' |
Specify the minimum value that the block outputs.
Default: []
The default value, [], is equivalent to Inf.
Simulink software uses this value to perform:
Simulation range checking (see Checking Signal Ranges)
Automatic scaling of fixed-point data types
Specify the maximum value the block outputs.
Default: []
The default value, [], is equivalent to Inf.
Simulink software uses this value to perform:
Parameter range checking (see Checking Parameter Values) for some blocks
Simulation range checking (see Checking Signal Ranges)
Automatic scaling of fixed-point data types
This number must be a double scalar value.
See Block-Specific Parameters for the command-line information.
Specify the output data type.
Default: Inherit: Inherit via internal rule
This option appears only for blocks (Discrete-Time Integrator, Gain, Product, Sum, Switch blocks). Simulink chooses a combination of output scaling and data type that requires the smallest amount of memory consistent with accommodating the calculated output range and maintaining the output precision of the block and with the word size of the targeted hardware implementation specified for the model.
If you set the Device type parameter on the Hardware Implementation configuration parameters pane to ASIC/FPGA, Simulink chooses the output data type without regard to hardware constraints. Otherwise, Simulink chooses the smallest available hardware data type capable of meeting the range and precision constraints. For example, if the block multiplies an input of type int8 by a gain of int16 and you specify ASIC/FPGA as the targeted hardware type, the output data type is sfix24. If you select Unspecified (assume 32-bit Generic) for a generic 32-bit microprocessor as the target hardware, the output data type is int32. If the word lengths provided by the target microprocessor cannot accommodate the output range, Simulink displays an error message in the Simulation Diagnostics Viewer.
Use data type of the Constant value parameter. This option appears only for the Constant block.
Uses the data type of the driving block (Data Type Conversion block).
Uses the data type of sole input signal. This option appears only for the Saturation block.
Uses the data type of the first input signal. This option appears only for some blocks.
Uses the accumulator data type for the output data type. This option appears only for some blocks.
Specifies output data type double.
Specifies output data type single.
Specifies output data type int8.
Specifies output data type uint8.
Specifies output data type int16.
Specifies output data type uint16.
Specifies output data type int32.
Specifies outputs data type unt32.
Specifies output data type fixed point fixdt(1,16,0).
Specifies output data type fixed point fixdt(1,16,2^0,0).
Uses an enumerated data type, for example, Enum: BasicColors. This option appears only for some blocks.
Uses a data type object, for example, Simulink.NumericType.
See Block-Specific Parameters for the command-line information.
Select the category of data to specify.
Default:
Inherit (Constant, Data Type Conversion, Discrete Time Integrator, Gain, Inport, Outport, Product, Saturation, Sum, Switch)
Built in (Logical Operator, Relational Operator)
Specifies inheritance rules for data types. Selecting Inherit enables a list of possible values, which can vary by block:
Inherit from 'Constant value' (Constant block default)
Inherit via internal rule (Discrete-Time Integrator, Gain, Product, Sum, Switch block default)
Inherit via back propogation (Data Type Conversion block default)
auto (Inport, Outport block default)
Logical (see Configuration Parameters: Optimization)
Same as first input
Same as input (Saturation block default)
Same as accumulator
Specifies built-in data types. Selecting Built in enables list of possible values, which can vary by block:
double (Constant, Data Type Conversion, Discrete-Time Integrator, Gain, Inport, Outport, Product, Saturation, Sum, Switch block default)
single
int8
uint8
int16
uint16
int32
uint32
boolean (Logical Operator, Relational Operator block default)
Fixed-point data types.
Enumerated data types. This option is available on some blocks. Selecting Enumerated enables a second menu/text box to the right. Following is a list of possible values, which can vary by block:
<class name>
Expressions that evaluate to data types. Selecting Expression enables a second menu/text box to the right. Following is a list of possible values, which can vary by block:
<data type expression>
Clicking the Show data type assistant button enables this parameter.
See Block-Specific Parameters for the command-line information.
See Using the Data Type Assistant in the Simulink User's Guide.
Specify fixed-point data as signed or unsigned.
Default: Signed
Selecting Mode > Fixed point enables this parameter.
See Block-Specific Parameters for the command-line information.
See Specifying a Fixed-Point Data Type in the Simulink User's Guide for more information.
Specify the bit size of the word that holds the quantized integer.
Default: 16
Minimum: 0
Maximum: 32
Large word sizes represent large values with greater precision than small word sizes.
Selecting Mode > Fixed point enables this parameter.
See Block-Specific Parameters for the command-line information.
See Specifying a Fixed-Point Data Type in the Simulink User's Guide for more information.
Specify the method for scaling your fixed-point data to avoid overflow conditions and minimize quantization errors.
Default:
Best precision (Constant),
Binary point (Data Type Conversion, Discrete-Time Integrator, Gain, Inport, Outport, Product, Saturation, Sum, Switch)
Integer (Logical Operator, Relational Operator)
Specifies binary point location.
Enters slope and bias.
Specifies best-precision values. This option appears for some blocks.
Specifies integer. This setting has the same result as specifying a binary point location and setting fraction length to 0. This option appears for some blocks.
Selecting Mode > Fixed point enables this parameter.
Selecting Binary point enables:
Fraction length
Calculate Best-Precision Scaling
Selecting Slope and bias enables:
Slope
Bias
Calculate Best-Precision Scaling
See Specifying a Fixed-Point Data Type in the Simulink User's Guide for more information.
Specify fraction length for fixed-point data type.
Default: 0
Binary points can be positive or negative integers.
Selecting Scaling > Binary point enables this parameter.
See Block-Specific Parameters for the command-line information.
See Specifying a Fixed-Point Data Type in the Simulink User's Guide for more information.
Specify slope for the fixed-point data type.
Default: 2^0
Specify any positive real number.
Selecting Scaling > Slope and bias enables this parameter.
See Block-Specific Parameters for the command-line information.
See Specifying a Fixed-Point Data Type in the Simulink User's Guide for more information.
Specify bias for the fixed-point data type.
Default: 0
Specify any real number.
Selecting Scaling > Slope and bias enables this parameter.
See Block-Specific Parameters for the command-line information.
See Specifying a Fixed-Point Data Type in the Simulink User's Guide for more information.
The Multiport Switch block is a bus-capable block. The data inputs can be virtual or nonvirtual bus signals subject to the following restrictions:
All the buses must be equivalent (same hierarchy with identical names and attributes for all elements).
All signals in a nonvirtual bus input to a Multiport Switch block must have the same sample time. This requirement holds even if the elements of the associated bus object specify inherited sample times.
You can use a Rate Transition block to change the sample time of an individual signal, or of all signals in a bus. See Using Composite Signals andBus-Capable Blocksfor more information.
| Bus-capable | Yes, with restrictions |
Direct Feedthrough | Yes |
Sample Time | Specified in the Sample time parameter |
Scalar Expansion | Yes |
Dimensionalized | Yes |
Multidimensionalized | Yes |
Zero Crossing | No |
![]() | Model Info | Mux | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |