Products & Services Solutions Academia Support User Community Company

Learn more about Simulink   

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

Rules That Determine the Block Output

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:

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 Zero-Based IndexingBlock 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.

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

The following table summarizes how the block defines the default output for an out-of-range control input.

Block UsageHow the Block Defines the Default Output
SimulationNone, because an out-of-range control input results in an error.
Real-Time Workshop generated codeUndefined
Accelerator modesUndefined

Related Blocks

The Index Vector block, also in the Signal Routing library, is another implementation of the Multiport Switch block that has different default parameter settings.

Data Type Support

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.

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:

Number of inputs

Default: 1

Specify the number of data inputs to the block.

Use zero-based indexing

Specify block indexing.

Settings

Default: Off

On

Uses zero-based indexing.

Off

Uses one-based indexing.

Sample time (-1 for inherited)

Specify the time interval between samples.

Settings

Default: -1

This setting indicates the block inherits the sample time.

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.

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

Select the rounding mode for fixed-point operations.

Settings

Default: Floor

Ceiling

Rounds toward positive infinity and is equivalent to the MATLAB ceil function.

Convergent

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.

Floor

Rounds toward negative infinity and is equivalent to the MATLAB floor function.

Nearest

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.

Round

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.

Simplest

Automatically chooses between round toward floor and round toward zero to produce generated code that is as efficient as possible

Zero

Rounds toward zero and is equivalent to the MATLAB fix function.

Saturate on integer overflow

Specify what to do with overflows.

Settings

Default: Off

On

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.

Off

Does not allow overflow to saturate.

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: AllowDiffInputSignals
Type: string
Value: 'on' | 'off'
Default: 'off'

Output minimum

Specify the minimum value that the block outputs.

Default: []

The default value, [], is equivalent to Inf.

Simulink software uses this value to perform:

Output maximum

Specify the maximum value the block outputs.

Settings

Default: []

The default value, [], is equivalent to Inf.

Simulink software uses this value to perform:

Tip

This number must be a 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

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.

Inherit: Inherit from 'Constant value'

Use data type of the Constant value parameter. This option appears only for the Constant block.

Inherit: Inherit via back propagation

Uses the data type of the driving block (Data Type Conversion block).

Inherit: Same as input

Uses the data type of sole input signal. This option appears only for the Saturation block.

Inherit: Same as first input

Uses the data type of the first input signal. This option appears only for some blocks.

Inherit: Same as accumulator

Uses the accumulator data type for the output data type. This option appears only for some blocks.

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 outputs data type unt32.

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

Enum: <class name>

Uses an enumerated data type, for example, Enum: BasicColors. This option appears only for some blocks.

<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

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

Built in

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

Fixed-point data types.

Enumerated

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>

Expression

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>

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.

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.

Dependencies

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.

Dependencies

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:

Binary point

Specifies binary point location.

Slope and bias

Enters slope and bias.

Best precision

Specifies best-precision values. This option appears for some blocks.

Integer

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.

Dependencies

Selecting Mode > Fixed point enables this parameter.

Selecting Binary point enables:

Selecting Slope and bias enables:

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.

Dependencies

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.

Dependencies

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.

Dependencies

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 andBus-Capable Blocksfor more information.

Characteristics

Bus-capableYes, with restrictions

Direct Feedthrough

Yes

Sample Time

Specified in the Sample time parameter

Scalar Expansion

Yes

Dimensionalized

Yes

Multidimensionalized

Yes

Zero Crossing

No

  


Related Products & Applications

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