| Simulink® | ![]() |
Switch output between first input and third input based on value of second input
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 Changing the Orientation of a Block in the Simulink® documentation for a description of the port order for various block orientations.)
You select the conditions under which the first input is passed with the Criteria for passing first input parameter. You can make the block check whether the control input is greater than or equal to the threshold value, purely greater than the threshold value, or nonzero. If the control input meets the condition set in the Criteria for passing first input parameter, the first input is passed. Otherwise, the third input is passed.
Note If the data inputs to the switch are buses, the element names of both buses must be the same to ensure that the output bus has the same element names no matter which input bus is selected. You can ensure that your model meets this requirement by using a bus object to define the buses with the model's Element name mismatch diagnostic set to error. See Connectivity Diagnostics Overview for more information. |
The control and data inputs of a Switch block can be signals of any data type supported by Simulink software, including fixed-point data types. However, the control input must be real; the data inputs can be real or complex.
For a discussion on the data types supported by Simulink software, see Data Types Supported by Simulink® in the Simulink documentation.
The Main pane of the Switch block dialog appears as follows:

Select the conditions under which the first input is passed. You can make the block check whether the control input is greater than or equal to the threshold value, purely greater than the threshold value, or nonzero. If the control input meets the condition set in this parameter, then the first input is passed. Otherwise, the third input is passed.
Assign the switch threshold that determines which input is passed to the output.
Select to enable zero crossing detection. For more information, see Zero Crossing Detection.
Specify the time interval between samples. To inherit the sample time, set this parameter to -1. See Specifying Sample Time in the online documentation for more information.
The Signal Attributes pane of the Switch block dialog appears as follows:

Select to require all data inputs to have the same data type.
Specify the minimum value that the block should output. 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 that the block should output. 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 output data type. You can set it to:
A rule that inherits a data type, for example, Inherit: Inherit via back propagation
The name of a built-in data type, for example, single
The name of a data type object, for example, a Simulink.NumericType object
An expression that evaluates to a data type, for example, float('single')
Click the Show data type assistant button
to display the Data
Type Assistant, which helps you set the Output
data type parameter.
See Specifying Block Output Data Types for more information.
Select to lock scaling of outputs. This parameter is visible only if you enter an expression for the Output data type parameter.
Select the rounding mode for fixed-point operations. For more information, see Rounding in the Simulink® Fixed Point™ User's Guide.
Select to have overflows saturate.
The Switch block is a bus-capable block. The inputs can be virtual or nonvirtual bus signals subject to the following restrictions:
The number of inputs must be greater than one.
All inputs to the merge must be buses and must be equivalent (same hierarchy with identical names and attributes for all elements).
| Bus-capable | Yes, with restrictions as noted above |
Direct Feedthrough | Yes |
Sample Time | Specified in the Sample time parameter |
Scalar Expansion | Yes |
Dimensionalized | Yes |
Multidimensionalized | Yes |
Zero Crossing | Yes, if enabled |
![]() | Sum, Add, Subtract, Sum of Elements | Switch Case | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |