| Contents | Index |
Signal Routing
The Multiport Switch block chooses among several inputs. The first input is the control input, while the others are data inputs. The value of the control input determines which data input passes to the output port.
Note This block is the same as the Index Vector block. If you set Number of data ports to 1, you get the Index Vector block. |
When you set Data port for default case to Additional data port, an extra data port with a * label appears below the other data inputs. For more information, see How the Block Handles an Out-of-Range Control Input.
You specify the number of data inputs with Number of data ports. Data inputs can be scalar or vector.
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 input vector element whose index matches the control input.
If you specify more than one data input, the block behaves as 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. In this case, 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 Data Port Order | Block Behavior During Simulation | |
|---|---|---|---|---|
| The specified data input passes to the output based on... | And an out-of-range error occurs when... | |||
Integer value | None | Zero-based contiguous | Zero-based indexing | The control input is less than 0 or greater than the number of data inputs minus one |
| One-based contiguous | One-based indexing | The control input is less than 1 or greater than the number of data inputs | ||
| Specify indices | Indices you specify | The control input does not correspond to any specified data port index | ||
Not an integer value | The block truncates the value to an integer by rounding to floor. | Zero-based contiguous | Zero-based indexing | The truncated control input is less than 0 or greater than the number of data inputs minus one |
| One-based contiguous | One-based indexing | The truncated control input is less than 1 or greater than the number of data inputs | ||
| Specify indices | Indices you specify | The truncated control input does not correspond to any specified data port index | ||
For a control input with an integer value, the input is out of range when the value does not match any data port indices. For a control input that is not an integer value, the input is out of range when the truncated value does not match any data port indices. In both cases, the block behavior depends on your settings for Data port for default case and Diagnostic for default case.
The following behavior applies only to simulation for your model.
| Data port for default case | Diagnostic for default case | ||
|---|---|---|---|
| None | Warning | Error | |
Last data port
| Use the last data port and do not report any warning or error. | Use the last data port and report a warning. | Report an error and stop simulation. |
Additional data port
| Use the additional data port with a * label and do not report any warning or error. | Use the additional data port with a * label and report a warning. | Report an error and stop simulation. |
The following behavior applies to code generation for your model.
| Data port for default case | Diagnostic for default case | ||
|---|---|---|---|
| None | Warning | Error | |
Last data port
| Use the last data port. | Use the last data port. | Use the last data port. |
Additional data port
| Use the additional data port with a * label. | Use the additional data port with a * label. | Use the additional data port with a * label. |
When the control port on the Multiport Switch block is of enumerated type, follow these guidelines:
| Scenario | What to Do | Rationale |
|---|---|---|
The enumerated type contains a value that represents invalid, out-of-range, or uninitialized values. |
| This block configuration handles invalid values that the enumerated type explicitly represents. |
The enumerated type contains only valid enumerated values. However, a data input port can get invalid values of enumerated type. |
| This block configuration handles invalid values that the enumerated type does not explicitly represent. |
The enumerated type contains only valid enumerated values. Data input ports can never get invalid values of enumerated type. |
| This block configuration avoids unnecessary diagnostic action. |
The block does not have a data input port for every value of the enumerated type. |
| This block configuration handles enumerated values that do not have a data input port, along with invalid values. |
The control signal can be of any data type that Simulink supports, including fixed-point and enumerated types. 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 information, 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:

Specify the type of ordering for your data input ports.
Default: One-based contiguous (for Multiport Switch block), Zero-based contiguous (for Index Vector block)
Block uses zero-based indexing for ordering contiguous data ports.
Block uses one-based indexing for ordering contiguous data ports.
Block uses noncontiguous indexing for ordering 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 slupdate on your model to replace each Multiport Switch block of this configuration with a block that explicitly specifies data port indices.
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... | You get... |
|---|---|
| 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.
See Block-Specific Parameters for the command-line information.
Specify the number of data input ports to the block.
Default: 3 (for Multiport Switch block), 1 (for Index Vector block)
The block icon changes to match the number of data input ports you specify.
Selecting Zero-based contiguous or One-based contiguous for Data port order enables this parameter.
See Block-Specific Parameters for the command-line information.
Specify an array of indices for your data ports.
Default: {1,2,3}
The block icon changes to match the data port indices you specify.
To specify an array of indices that correspond to all values of an enumerated type, enter enumeration('type_name') for this parameter. Do not include braces.
For example, enumeration('MyColors') is a valid entry.
To enter specific values of an enumerated type, use the type_name.enumerated_name format. Do not enter the underlying integer value.
For example, {MyColors.Red, MyColors.Green, MyColors.Blue} is a valid entry.
To indicate that more than one value maps to a data port, use brackets.
For example, the following entries are both valid:
{MyColors.Red, MyColors.Green, [MyColors.Blue, MyColors.Yellow]}
{[3,5],0,18}
If the control port is of fixed-point or built-in data type, the values for Data port indices must be representable with that type. Otherwise, an error appears at compile time to alert you to unused data ports.
If the control port is of enumerated data type, the values for Data port indices must be enumerated values of that type.
If Data port indices contains values of enumerated type, the control port must be of that data type.
Selecting Specify indices for Data port order enables this parameter.
See Block-Specific Parameters for the command-line information.
Specify whether to use the last data port for out-of-range inputs, or to use an additional port.
Default: Last data port
Block uses the last data port for output when the control port value does not match any data port indices.
Block uses an additional data port for output when the control port value does not match any data port indices.
If you set this parameter to Additional data port and Number of data ports is 3, the number of input ports on the block is 5. The first input is the control port, the next three inputs are data ports, and the fifth input is the default port for out-of-range inputs.
See Block-Specific Parameters for the command-line information.
Specify the diagnostic action to take when the control port value does not match any data port indices.
Default: Error
Do not show any warning or error message.
Show a warning message in the MATLAB Command Window and continue the simulation.
Show an error message in the Simulation Diagnostics Viewer and stop the simulation. In this case, the Data port for default case is used only for code generation and not simulation.
For more information, see How the Block Handles an Out-of-Range Control Input.
See Block-Specific Parameters for the command-line information.
Enter the discrete interval between sample time hits or specify another appropriate sample time such as continuous or inherited.
Default: -1
By default, the block inherits its sample time based upon the context of the block within the model. To set a different sample time, enter a valid sample time based upon the table in Types of Sample Time.
See also How to Specify the Sample Time in the online documentation for more information.
See Block-Specific Parameters for the command-line information.
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.
See Block-Specific Parameters for the command-line information.
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.
Specify the rounding mode for fixed-point operations.
Default: Floor
Rounds both positive and negative numbers toward positive infinity. Equivalent to the MATLAB ceil function.
Rounds number to the nearest representable value. If a tie occurs, rounds to the nearest even integer. Equivalent to the Fixed-Point Toolbox convergent function.
Rounds both positive and negative numbers toward negative infinity. Equivalent to the MATLAB floor function.
Rounds number to the nearest representable value. If a tie occurs, rounds toward positive infinity. Equivalent to the Fixed-Point Toolbox nearest function.
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 Toolbox round function.
Automatically chooses between round toward floor and round toward zero to generate rounding code that is as efficient as possible.
Rounds number toward zero. Equivalent to the MATLAB fix function.
See Block-Specific Parameters for the command-line information.
For more information, see Rounding in the Simulink Fixed Point User's Guide.
Specify whether overflows saturate.
Default: Off
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.
Overflows wrap to the appropriate value that is representable by the data type.
For example, the number 130 does not fit in a signed 8-bit integer and wraps to -126.
Consider selecting this check box when your model has 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 avoid overspecifying how a block handles out-of-range signals. For more information, see Checking for 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.
See Block-Specific Parameters for the command-line information.
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: AllowDiffInputSize |
| Type: string |
| Value: 'on' | 'off' |
| Default: 'off' |
Specify the minimum value that the block outputs.
Default: []
The default value is [] (unspecified).
Simulink uses this value to perform:
Simulation range checking (see Signal Ranges)
Automatic scaling of fixed-point data types
This number must be a finite real double scalar value.
See Block-Specific Parameters for the command-line information.
Specify the maximum value the block outputs.
Default: []
The default value is [] (unspecified).
Simulink uses this value to perform:
Simulation range checking (see Signal Ranges)
Automatic scaling of fixed-point data types
This number must be a finite real double scalar value.
See Block-Specific Parameters for the command-line information.
Specify the output data type.
Default: Inherit: Inherit via internal rule
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.
Uses the data type of the driving block.
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 output data type uint32.
Specifies output data type fixed point fixdt(1,16,0).
Specifies output data type fixed point fixdt(1,16,2^0,0).
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
Specifies inheritance rules for data types. Selecting Inherit enables a list of possible values:
Inherit via internal rule (default)
Inherit via back propagation
Specifies built-in data types. Selecting Built in enables a list of possible values:
double (default)
single
int8
uint8
int16
uint16
int32
uint32
Specifies fixed-point data types.
Specifies expressions that evaluate to data types. Selecting Expression enables you to enter an 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 data type override mode for this signal.
Default: Inherit
Inherits the data type override setting from its context, that is, from the block, Simulink.Signal object or Stateflow chart in Simulink that is using the signal.
Ignores the data type override setting of its context and uses the fixed-point data type specified for the signal.
The ability to turn off data type override for an individual data type provides greater control over the data types in your model when you apply data type override. For example, you can use this option to ensure that data types meet the requirements of downstream blocks regardless of the data type override setting.
This parameter appears only when the Mode is Built in or Fixed point.
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
Specify binary point location.
Enter slope and bias.
Specify best-precision values.
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 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 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 when 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 and Bus-Capable Blocks for more information.
You can use an array of buses as an input signal to a Multiport Switch block. For details about defining and using an array of buses, see Combining Buses into an Array of Buses. When you use an array of buses with a Multiport Switch block, set Number of data ports to a value of 2 or greater.
The sf_aircontrol model uses a Multiport Switch block in the Physical Plant subsystem. This block uses zero-based indexing for contiguous ordering of three data ports.

The indices are visible on the data port labels. You do not have to open the block dialog box to determine whether the data ports use zero-based or one-based indexing.
When you set Data port for default case to Last data port, the last data port includes a * on the label. The comma after the * indicates that the data port index has a value. This port corresponds to the default case, which applies when the control input does not match the data port indices 0, 1, or 2. In this case, the Multiport Switch block outputs a value of –0.1.
The sf_semantics_hotel_checkin model uses a Multiport Switch block. This block uses one-based indexing for contiguous ordering of three data ports.

If you increase the size of the block icon, the indices are visible on the data port labels. You do not have to open the block dialog box to determine whether the data ports use zero-based or one-based indexing.
The sldemo_fuelsys model uses a Multiport Switch block in the fuel_rate_control/fuel_calc/feedforward_fuel_rate subsystem. This block uses the enumerated type sld_FuelModes to specify three data port indices: LOW, RICH, and DISABLED.

When you set Data port for default case to Last data port, the last data port includes a * on the label. The comma and ellipsis after the * indicate that the data port index has a value. This port corresponds to the default case, which applies when the control input does not match the data port indices LOW, RICH, or DISABLED. In this case, the Multiport Switch block outputs a value of 0.
The following model uses a Multiport Switch block that specifies noncontiguous integer values for data ports.

The values of the indices are visible on the data port labels. You do not have to open the block dialog box to determine which value maps to each data port.
When you set Data port for default case to Additional data port, an extra port with a * label appears. This port corresponds to the default case, which applies when the control input does not match the data port indices 3, 5, 0, or 18. In this case, the Multiport Switch block outputs a value of 1.
The following model uses two Index Vector blocks that specify zero-based and one-based indexing, respectively.

If the value of the control input is not an integer, the block truncates the value by rounding to floor. For more information, see How the Block Interprets the Control Input.
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 Detection | No |

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