| 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 Switch block passes through the first input or the third input based on the value of the second input. The first and third inputs are called data inputs. The second input is called the control input. See How to Rotate a Block in the Simulink User's Guide for a description of the port order for various block orientations.
You select the condition under which the block passes the first input with the Criteria for passing first input parameter.
Note If the data inputs to the switch are buses, the element names of both buses must be the same. Using the same element names ensures that the output bus has the same element names no matter which input bus the block selects. You can ensure that your model meets this requirement by using a bus object to define the buses with the model Element name mismatch diagnostic set to error. See Connectivity Diagnostics Overview for more information. |
To immediately back propagate a known output data type to the first and third input ports, set the Output data type parameter to Inherit: Inherit via internal rule and select the Require all data port inputs to have the same data type check box.
The control signal can be of any data type that Simulink supports, including fixed-point and enumerated types. The control signal cannot be complex. If the control signal is enumerated, the block Threshold parameter must be a value of the same enumerated type.
The data signals can be of any data type that Simulink supports. If either data signal is of an enumerated type, the other must be of the same enumerated type.
For more information, see Data Types Supported by Simulink in the Simulink User's Guide.
The Main pane of the Switch block dialog box appears as follows:

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

Select the condition under which the block passes the first input. If the control input meets the condition set in the Criteria for passing first input parameter, the block passes the first input. Otherwise, the block passes the third input.
Default: u2 >= Threshold
Checks whether the control input is greater than or equal to the threshold value.
Checks whether the control input is greater than the threshold value.
Checks whether the control input is nonzero.
When the control input is a Boolean signal, use one of these combinations of condition and threshold value:
u2 >= Threshold, where the threshold value equals 1
u2 > Threshold, where the threshold value equals 0
u2 ~=0
Otherwise, the Switch block ignores threshold values and uses the Boolean value for signal routing. For a value of 1, the block passes the first input, and for a value of 0, the block passes the third input. A warning message that describes this behavior also appears in the MATLAB Command Window.
Selecting u2 ~=0 disables the Threshold parameter.
See Block-Specific Parameters for the command-line information.
Assign the switch threshold that determines which input the block passes to the output.
Default: 0
Minimum: value from the Output minimum parameter
Maximum: value from the Output maximum parameter
Setting Criteria for passing first input to u2 ~=0 disables this parameter.
See Block-Specific Parameters for the command-line information.
Select to enable zero-crossing detection.
Default: On
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 Block-Specific Parameters for the command-line information.
Require all data inputs to have the same data type.
Default: Off
Requires all data inputs to have the same data type.
Does not require all data inputs to have the same data type.
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.
Select the rounding mode for fixed-point operations.
Default: Floor
Rounds both positive and negative numbers toward positive infinity.
Rounds number to the nearest representable value. If a tie occurs, round to the nearest even stored value.
Rounds both positive and negative numbers toward negative infinity.
Rounds number to the nearest representable value. If a tie occurs, round toward positive infinity.
Rounds number to the nearest representable value. If a tie occurs, round positive numbers toward positive infinity and round negative numbers toward negative infinity.
Provides for an optimization of the rounding code for several blocks.
Rounds number toward zero.
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
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 which case, no saturation code is necessary.
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 propagates the input signal size to the output signal.
Inputs signals must be the same size.
| Parameter: AllowDiffInputSignals |
| Type: string |
| Value: 'on' | 'off' |
| Default: 'off' |
Specify the minimum value that the block should output.
Default: []
The default value, [], is equivalent to -Inf.
Simulink 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 maximum value that the block should output.
Default: []
The default value, [], is equivalent to Inf.
Simulink 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 (Discrete-Time Integrator, Gain, Product, Sum, Switch block)
Inherit: Inherit from 'Constant value' (Constant block)
Inherit: Inherit via back propagation (Data Type Conversion block)
Inherit: Same as input (Saturation block)
This option appears only for some blocks. Simulink chooses a combination of output scaling and data type that requires the smallest amount of memory. The choices are consistent with accommodating the calculated output range, maintaining the output precision of the block, and 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 none of the word lengths provided by the target microprocessor can accommodate the output range, Simulink displays an error message in the Simulation Diagnostics Viewer.
Usees data type of Constant value parameter. This option appears only for some blocks.
Uses data type of the driving block.
Uses data type of sole input signal. This option appears only for some blocks.
Uses data type of first input signal. This option appears only for some blocks.
Specifies output data type is the same as accumulator data type. This option appears for some blocks.
Specifies output data type is double.
Specified output data type is single.
Specifies output data type is int8.
Specifies output data type is uint8.
Specifies output data type is int16.
Specifies output data type is uint16.
Specifies output data type is int32.
Specifies output data type is unt32.
Specifies output data type is fixed point fixdt(1,16,0).
Specifies output data type is 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.
See Specifying Block Output Data Types in the Simulink User's Guide for more 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 a 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)
Specifies fixed-point data types.
Specifies enumerated data types. This option is available only on some blocks. Selecting Enumerated enables a list of possible values, which can vary by block:
<class name>
Specifies expressions that evaluate to data types. Selecting Expression enables 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 whether you want the 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 only for some blocks.
Specify 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 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 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 Switch block must have the same sample time. The 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 and Bus-Capable Blocks for 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 Detection | Yes, if enabled |
![]() | Sum, Add, Subtract, Sum of Elements | Switch Case | ![]() |

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 |