Switch
Switches the output between the first and third inputs based on the value of the second input.
Description
The Switch block passes the signal from the first or third input depending on the value of the signal on the second input. The first and third inputs are input signals, the second input is a control signal. The condition under which the block passes the signal from the first input to the output is set by the Criteria for passing first input and Threshold parameters.
Ports
Input
Port_1 - first input signal
scalar
| vector
The first of two input signals. The block passes either one or the other input signal to the output based on the value of the control signal. The condition under which the block passes the signal from the first input to the output is specified by the Criteria for passing first input and Threshold parameters.
Data types: Float16
, Float32
, Float64
, Int8
, Int16
, Int32
, Int64
, Int128
, UInt8
, UInt16
, UInt32
, UInt64
, UInt128
, Bool
, Fixed
.
Support for complex numbers: Yes
Port_2 - control signal
scalar
| vector
The control signal that the block uses to determine which input should be passed to the output. If the control signal satisfies the conditions specified in Criteria for passing first input, the block passes the first input signal. Otherwise, the block passes the second input signal.
Data types: Float16
, Float32
, Float64
, Int8
, Int16
, Int32
, Int64
, Int128
, UInt8
, UInt16
, UInt32
, UInt64
, UInt128
, Bool
, Fixed
.
Support for complex numbers: No
Port_3 - second input signal
scalar
| vector
The second of two input signals. The block passes either one or the other input signal to the output based on the value of the control signal. The condition under which the block passes the signal from the first input to the output is specified by the Criteria for passing first input and Threshold parameters.
Data types: Float16
, Float32
, Float64
, Int8
, Int16
, Int32
, Int64
, Int128
, UInt8
, UInt16
, UInt32
, UInt64
, UInt128
, Bool
, Fixed
.
Support for complex numbers: Yes
Output
Port_1 - output signal
scalar
| vector
Output signal derived from either the first or the second input signal, depending on the value of the control signal.
Data types: Float16
, Float32
, Float64
, Int8
, Int16
, Int32
, Int64
, Int128
, UInt8
, UInt16
, UInt32
, UInt64
, UInt128
, Bool
, Fixed
.
Support for complex numbers: Yes
Parameters
Main
Criteria for passing first input - criterion for selecting the passing of the first input signal
u2 > Threshold
(by default) | u2 >= Threshold
| u2 ~= 0
Select the condition that causes the block to pass the first input signal to the output. If the control input Port_2 satisfies the conditions specified in Criteria for passing first input, the block will pass the first input signal to Port_1. Otherwise, the block will pass the second input signal Port_3. Options for selection:
-
u2 >= Threshold
- the control input is greater than or equal to the threshold value; -
u2 > Threshold
- the control input is greater than the threshold value; -
u2 ~= 0
- the control input is different from zero.
Hint
If the control input is a Boolean signal, use one of the following combinations of condition and threshold value:
-
u2 >= Threshold
where the threshold value is1
; -
u2 > Threshold
, where the threshold value is0
; -
u2 ~= 0
.
Otherwise, the Switch block ignores the threshold values and uses a boolean value to route the signal. At a value of 1
, the block routes the first input, and at a value of 0
, it routes the third input.
Block parameter |
|
Value |
|
* By default* |
|
*Threshold` is the threshold value used in the criterion
0 (by default)
| scalar
| vector
| matrix
| array
The threshold value used in the Criteria for passing first input parameter, which determines which input the block passes to the output.
Dependencies
To use this parameter, set the Criteria for passing first input parameter to u2 >= Threshold
or u2 > Threshold
.
Block parameter |
|
Value |
|
By default |
|
Signal Attributes
Require all data port inputs to have the same data type - all data inputs must have the same data type
disabled (by default)
| enabled
Enable this parameter so that all data inputs have the same data type.
Block parameter |
|
Value |
|
* By default* |
|
Output data type - output data type
Inherit: auto (by default)
| Same as first input
| Float16
| Float32
| Float64
| Int8
| Int16
| Int32
| Int64
| Int128
| UInt8
| UInt16
| UInt32
| UInt64
| UInt128
| Fixed point
| Bool
Specify the type of output data.
The type can be inherited or specified directly.
Block parameter |
|
Values |
|
By default |
|
Integer rounding mode - rounding mode for fixed point operations
Floor (by default)
| Ceiling
| Convergent
| Nearest
| Round
| | Zero
Select the rounding mode for fixed point operations. You can select:
-
Floor
- rounds both positive and negative numbers downwards (towards negative infinity). -
Ceiling
- rounds both positive and negative numbers upwards (towards positive infinity). -
Convergent
- rounds a number to the nearest representable value. If the fractional part of a number ends in 5, the number is rounded to the nearest even integer. -
Nearest
- rounds the number to the nearest representable value. If the fractional part of the number ends in 5, the number is rounded upwards (towards positive infinity). -
Round
- rounds the number to the nearest representable value. If the fractional part of a number ends in 5, positive numbers are rounded upwards (towards positive infinity) and negative numbers are rounded downwards (towards negative infinity).
-
Zero
- rounds the number towards zero.
The block parameters are always rounded to the nearest representable value.
Block parameter |
|
Value |
|
By default |
|
Saturate on integer overflow - saturation to integer on overflow
выключено (by default)
| включено
A checkbox which, when selected, uses saturation arithmetic for integers and fixed-point numbers: when an overflow occurs, the result is automatically replaced by the maximum possible (modulo) value for the data type.
Action | Rationale | Effect on overflow | Example |
---|---|---|---|
The checkbox Saturate on integer overflow is checked (enabled). |
Overflow is possible for your model and you want the generated code to have an explicit overflow protection. |
If an overflow occurs, the result is automatically replaced by the maximum possible (modulo) value for the data type. |
The maximum value that can be represented by the data type Any result of a block operation that exceeds this maximum value results in an 8-bit integer overflow. When checked, the block output is saturated to 127. Similarly, the block output is saturated at a minimum output value of -128. |
The Saturate on integer overflow checkbox is unchecked (disabled). |
You want to optimise the efficiency of your generated code. You want to avoid over-determining how the block handles out-of-range signals. |
Overflows are carried in an appropriate value that can be represented by a data type. |
The maximum value that can be represented by the data type Any result of a block operation that exceeds this maximum value results in an 8-bit integer overflow. If the check box is unchecked, software interprets the value causing the overflow as |
When you select this check box, saturation is applied to all internal operations in the block, not just the input/output data or the result.
Block parameter |
|
Value |
|
By default |
|