| Contents | Index |
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. Specify the condition under which the block passes the first input by using the Criteria for passing first input and Threshold parameters.
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 sizes of the two data inputs can be different if you select Allow different data input sizes on the block dialog box. However, this block does not support variable-size input signals. Therefore, the size of each input cannot change during simulation.
If the data inputs to the Switch block 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. To ensure that your model meets this requirement, use a bus object to define the buses and set the Element name mismatch diagnostic to error. See Connectivity Diagnostics Overview for more information.
The block icon helps you identify Criteria for passing first input and Threshold without having to open the block dialog box.
For information about port order for various block orientations, see How to Rotate a Block in the Simulink documentation.
When the control input is a Boolean signal, use one of these combinations of criteria 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 the threshold and uses the Boolean input for signal routing. For a control input of 1, the block passes the first input, and for a control input of 0, the block passes the third input. In this case, the block icon changes after compile time and uses T and F to label the first and third inputs, respectively.
The control input can be of any data type that Simulink supports, including fixed-point and enumerated types. The control input cannot be complex. If the control input is enumerated, the Threshold parameter must be a value of the same enumerated type.
The data inputs can be of any data type that Simulink supports. If either data input is of an enumerated type, the other must be of the same enumerated type.
When the output is of enumerated type, both data inputs should use the same enumerated type as the output.
For more information, see Data Types Supported by Simulink in the Simulink documentation.
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
To specify a nonscalar threshold, use brackets. For example, the following entries are valid:
[1 4 8 12]
[MyColors.Red, MyColors.Blue]
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. For more information, see 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 also How to Specify the Sample Time in the online documentation for more information.
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.
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 propagates the input signal size to the output signal. If the two data inputs are variable-size signals, the maximum size of the signals can be equal or different.
Inputs signals must be the same size.
| Parameter: AllowDiffInputSize |
| Type: string |
| Value: 'on' | 'off' |
| Default: 'off' |
Specify the minimum value that the block should output.
Default: []
The default value is [] (unspecified).
Simulink uses this value to perform:
Parameter range checking (see Checking Parameter Values) for some blocks
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 that the block should output.
Default: []
The default value is [] (unspecified).
Simulink uses this value to perform:
Parameter range checking (see Checking Parameter Values) for some blocks
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
Uses the following rules to determine the output data type.
| Data Type of First Input Port | Output Data Type |
|---|---|
| Has a larger positive range than the third input port | Inherited from the first input port |
| Has the same positive range as the third input port | Inherited from the third input port |
| Has a smaller positive range than the third input port |
Uses data type of the driving block.
Specifies output data type is double.
Specifies 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 uint32.
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.
Uses a data type object, for example, Simulink.NumericType.
When the output is of enumerated type, both data inputs should use the same enumerated type as the output.
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
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 enumerated data types. Selecting Enumerated enables you to enter a class name.
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 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
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 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.
You can use an array of buses as an input signal to a Switch block. For details about defining and using an array of buses, see Combining Buses into an Array of Buses. When using an array of buses with a Switch block, set the Threshold parameter to a scalar value.
In the sldemo_fuelsys model, the fuel_rate_control/airflow_calc subsystem uses a Switch block:

The value of the control port on the Switch block determines whether or not feedback correction occurs. The control port value depends on the output of the Logical Operator block.
| When the Logical Operator block output is... | The control port of the Switch block is... | And feedback control... |
|---|---|---|
| TRUE | 1 | Occurs |
| FALSE | 0 | Does not occur |
The sldemo_zeroxing model uses a Switch block:

The value of the control port on the Switch block determines when the output changes from the first input to the third input.
| When simulation time is... | The Switch block output is... |
|---|---|
| Less than or equal to 5 | The first input from the Abs block |
| Greater than 5 | The third input from the Saturation block |
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 |

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 |