Skip to Main Content Skip to Search
Product Documentation

Multiport Switch - Choose between multiple block inputs

Library

Signal Routing

Description

Types of Block Inputs

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.

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.

Rules That Determine the Block Output

You specify the number of data inputs with Number of data ports. Data inputs can be scalar or vector.

How the Block Interprets the Control Input

The following table summarizes how the block interprets the control input and passes data to the output.

Control InputTruncationSetting for Data Port OrderBlock 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

How the Block Handles an Out-of-Range Control Input

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.

Behavior for Simulation

The following behavior applies only to simulation for your model.

Data port for default caseDiagnostic for default case
NoneWarningError

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.

Behavior for Code Generation

The following behavior applies to code generation for your model.

Data port for default caseDiagnostic for default case
NoneWarningError

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.

Guidelines on Setting Parameters for Enumerated Control Port

When the control port on the Multiport Switch block is of enumerated type, follow these guidelines:

ScenarioWhat to DoRationale

The enumerated type contains a value that represents invalid, out-of-range, or uninitialized values.

  • Set Data port order to Specify indices.

  • Set Data port indices to use this value for the last data port.

  • Set Data port for default case to Last data port.

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.

  • Set Data port for default case to Additional data port.

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.

  • Set Data port for default case to Last data port.

  • Set Diagnostic for default case to None.

This block configuration avoids unnecessary diagnostic action.

The block does not have a data input port for every value of the enumerated type.

  • Set Data port for default case to Additional data port.

This block configuration handles enumerated values that do not have a data input port, along with invalid values.

Data Type Support

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.

Parameters and Dialog Box

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:

Data port order

Specify the type of ordering for your data input ports.

Settings

Default: One-based contiguous (for Multiport Switch block), Zero-based contiguous (for Index Vector block)

Zero-based contiguous

Block uses zero-based indexing for ordering contiguous data ports.

One-based contiguous

Block uses one-based indexing for ordering contiguous data ports.

Specify indices

Block uses noncontiguous indexing for ordering data ports.

Tips

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.

Command-Line Information

See Block-Specific Parameters for the command-line information.

Number of data ports

Specify the number of data input ports to the block.

Settings

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.

Dependency

Selecting Zero-based contiguous or One-based contiguous for Data port order enables this parameter.

Command-Line Information

See Block-Specific Parameters for the command-line information.

Data port indices

Specify an array of indices for your data ports.

Settings

Default: {1,2,3}

The block icon changes to match the data port indices you specify.

Tips

Dependency

Selecting Specify indices for Data port order enables this parameter.

Command-Line Information

See Block-Specific Parameters for the command-line information.

Data port for default case

Specify whether to use the last data port for out-of-range inputs, or to use an additional port.

Settings

Default: Last data port

Last data port

Block uses the last data port for output when the control port value does not match any data port indices.

Additional data port

Block uses an additional data port for output when the control port value does not match any data port indices.

Tip

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.

Command-Line Information

See Block-Specific Parameters for the command-line information.

Diagnostic for default case

Specify the diagnostic action to take when the control port value does not match any data port indices.

Settings

Default: Error

None

Do not show any warning or error message.

Warning

Show a warning message in the MATLAB Command Window and continue the simulation.

Error

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.

Command-Line Information

See Block-Specific Parameters for the command-line information.

Sample time (-1 for inherited)

Enter the discrete interval between sample time hits or specify another appropriate sample time such as continuous or inherited.

Settings

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.

Command-Line Information

See Block-Specific Parameters for the command-line information.

Require all data port inputs to have the same data type

Specify allowed data types.

Settings

Default: Off

On

Requires all data port inputs to have the same data type.

Off

Allows data port inputs to have different data types.

Command-Line Information

See Block-Specific Parameters for the command-line information.

Lock output data type setting against changes by the fixed-point tools

Select to lock the output data type setting of this block against changes by the Fixed-Point Tool and the Fixed-Point Advisor.

Settings

Default: Off

On

Locks the output data type setting for this block.

Off

Allows the Fixed-Point Tool and the Fixed-Point Advisor to change the output data type setting for this block.

Command-Line Information

See Block-Specific Parameters for the command-line information.

See Also

For more information, see Fixed-Point Tool and Fixed-Point Advisor in the Simulink Fixed Point documentation.

Integer rounding mode

Specify the rounding mode for fixed-point operations.

Settings

Default: Floor

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

Command-Line Information

See Block-Specific Parameters for the command-line information.

See Also

For more information, see Rounding in the Simulink Fixed Point User's Guide.

Saturate on integer overflow

Specify whether overflows saturate.

Settings

Default: Off

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.

Off

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.

Tips

Command-Line Information

See Block-Specific Parameters for the command-line information.

Allow different data input sizes

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

Settings

Default: Off

On

Allows input signals with different sizes, and propagate the input signal size to the output signal.

Off

Requires that input signals be the same size.

Command-Line Information

Parameter: AllowDiffInputSize
Type: string
Value: 'on' | 'off'
Default: 'off'

Output minimum

Specify the minimum value that the block outputs.

Settings

Default: []

The default value is [] (unspecified).

Simulink uses this value to perform:

Tip

This number must be a finite real double scalar value.

Command-Line Information

See Block-Specific Parameters for the command-line information.

Output maximum

Specify the maximum value the block outputs.

Settings

Default: []

The default value is [] (unspecified).

Simulink uses this value to perform:

Tip

This number must be a finite real double scalar value.

Command-Line Information

See Block-Specific Parameters for the command-line information.

Output data type

Specify the output data type.

Settings

Default: Inherit: Inherit via internal rule

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.

Inherit: Inherit via back propagation

Uses the data type of the driving block.

double

Specifies output data type double.

single

Specifies output data type single.

int8

Specifies output data type int8.

uint8

Specifies output data type uint8.

int16

Specifies output data type int16.

uint16

Specifies output data type uint16.

int32

Specifies output data type int32.

uint32

Specifies output data type uint32.

fixdt(1,16,0)

Specifies output data type fixed point fixdt(1,16,0).

fixdt(1,16,2^0,0)

Specifies output data type fixed point fixdt(1,16,2^0,0).

<data type expression>

Uses a data type object, for example, Simulink.NumericType.

Command-Line Information

See Block-Specific Parameters for the command-line information.

Mode

Select the category of data to specify.

Settings

Default: Inherit

Inherit

Specifies inheritance rules for data types. Selecting Inherit enables a list of possible values:

  • Inherit via internal rule (default)

  • Inherit via back propagation

Built in

Specifies built-in data types. Selecting Built in enables a list of possible values:

  • double (default)

  • single

  • int8

  • uint8

  • int16

  • uint16

  • int32

  • uint32

Fixed point

Specifies fixed-point data types.

Expression

Specifies expressions that evaluate to data types. Selecting Expression enables you to enter an expression.

Dependency

Clicking the Show data type assistant button enables this parameter.

Command-Line Information

See Block-Specific Parameters for the command-line information.

See Also

See Using the Data Type Assistant in the Simulink User's Guide.

Data type override

Specify data type override mode for this signal.

Settings

Default: Inherit

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.

Off

Ignores the data type override setting of its context and uses the fixed-point data type specified for the signal.

Tip

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.

Dependency

This parameter appears only when the Mode is Built in or Fixed point.

Signedness

Specify fixed-point data as signed or unsigned.

Settings

Default: Signed

Signed

Specifies the fixed-point data as signed.

Unsigned

Specifies the fixed-point data as unsigned.

Dependency

Selecting Mode > Fixed point enables this parameter.

Command-Line Information

See Block-Specific Parameters for the command-line information.

See Also

See Specifying a Fixed-Point Data Type in the Simulink User's Guide for more information.

Word length

Specify the bit size of the word that holds the quantized integer.

Settings

Default: 16

Minimum: 0

Maximum: 32

Large word sizes represent large values with greater precision than small word sizes.

Dependency

Selecting Mode > Fixed point enables this parameter.

Command-Line Information

See Block-Specific Parameters for the command-line information.

See Also

See Specifying a Fixed-Point Data Type in the Simulink User's Guide for more information.

Scaling

Specify the method for scaling your fixed-point data to avoid overflow conditions and minimize quantization errors.

Settings

Default: Best precision

Binary point

Specify binary point location.

Slope and bias

Enter slope and bias.

Best precision

Specify best-precision values.

Dependencies

Selecting Mode > Fixed point enables this parameter.

Selecting Binary point enables:

Selecting Slope and bias enables:

Command-Line Information

See Block-Specific Parameters for the command-line information.

See Also

See Specifying a Fixed-Point Data Type in the Simulink User's Guide for more information.

Fraction length

Specify fraction length for fixed-point data type.

Settings

Default: 0

Binary points can be positive or negative integers.

Dependency

Selecting Scaling > Binary point enables this parameter.

Command-Line Information

See Block-Specific Parameters for the command-line information.

See Also

See Specifying a Fixed-Point Data Type in the Simulink User's Guide for more information.

Slope

Specify slope for the fixed-point data type.

Settings

Default: 2^0

Specify any positive real number.

Dependency

Selecting Scaling > Slope and bias enables this parameter.

Command-Line Information

See Block-Specific Parameters for the command-line information.

See Also

See Specifying a Fixed-Point Data Type in the Simulink User's Guide for more information.

Bias

Specify bias for the fixed-point data type.

Settings

Default: 0

Specify any real number.

Dependency

Selecting Scaling > Slope and bias enables this parameter.

Command-Line Information

See Block-Specific Parameters for the command-line information.

See Also

See Specifying a Fixed-Point Data Type in the Simulink User's Guide for more information.

Bus Support

The Multiport Switch block is a bus-capable block. The data inputs can be virtual or nonvirtual bus signals subject to the following restrictions:

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.

Examples

Zero-Based Indexing for Data Ports

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.

One-Based Indexing for Data Ports

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.

Enumerated Names for Data Port Indices

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.

Noncontiguous Values for Data Port Indices

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.

Behavior for an Index Vector Block

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.

Characteristics

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

See Also

Switch

  


Related Products & Applications

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