Subsystem whose execution is enabled by an If block
Simulink / Ports & Subsystems
The If Action Subsystem block is a Subsystem block preconfigured as a starting point for creating a subsystem whose execution is controlled by an If block. The If block evaluates a logical expression and then, depending on the result of the evaluation, outputs an action signal.
Simulink ignores a priority set on an If Action Subsystem block. Instead, set the priority on the If block that initiates execution of the subsystem.
This example shows how to merge signals controlled by an If
block. The If block selects the execution of an If Action Subsystem block from a set
of subsystems. Regardless of which subsystem the If block selects, you can create a
single signal with a Merge block. Open model
.
All blocks in an If Action Subsystem block must execute at the same rate as the driving If block. You can satisfy this requirement by setting the sample time parameter for each block to either inherited (-1) or the same value as the If block sample time.
The If block does not directly support fixed-point data types. However, you can use the Compare To Constant block to work around this limitation.
Consider the following floating-point model without fixed-point data types:
In this model, the If Action Subsystem blocks use their default configurations. The simulation parameters are set to their default values except for the parameters listed in the following table.
Configuration Parameter Pane | Parameter | Setting |
---|---|---|
Solver | Start time |
|
Stop time |
| |
Type |
| |
Solver |
| |
Fixed-step size |
|
The block parameters are set to their default values except for the parameters listed in the following table.
Block | Parameter | Setting |
---|---|---|
Repeating Sequence Stair | Vector of output values |
|
Repeating Sequence Stair1 | Vector of output values |
|
If | Number of inputs |
|
If expression |
| |
Show else condition | Selected | |
Constant | Constant value |
|
Constant1 | Constant value |
|
Scope | Number of axes |
|
Time range |
|
For this model, when input u1
is greater than
0
or input u2
is greater than
0.5
, the output is 4
. Otherwise, the
output is -4
. The Scope block displays the output
from the Merge block with inputs u1
, and
u2
.
You can implement this block diagram as a model with fixed-point data types:
The Repeating Sequence Stair blocks output fixed-point data types.
The Compare To Constant blocks implement two parts of the If expression that is used in the If block
in the floating-point version of the model, (u1 > 0)
and
(u2 > 0.5)
. The OR
operation,
(u1|u2)
, can still be implemented inside the
If block. For a fixed-point model, the expression must be
partially implemented outside of the If block as it is in this
model.
The block and simulation parameters for the fixed-point model are the same as for the floating-point model with the following exceptions and additions:
Block | Parameter | Setting |
---|---|---|
Compare To Constant | Operator |
|
Constant value |
| |
Output data type mode |
| |
Enable zero-crossing detection | off | |
Compare To Constant1 | Operator |
|
Constant value |
| |
Output data type mode |
| |
Enable zero-crossing detection | off | |
If | Number of inputs |
|
If expression |
|
Data Types |
|
Direct Feedthrough |
|
Multidimensional Signals |
|
Variable-Size Signals |
|
Zero-Crossing Detection |
|
[a] Actual data type or capability support depends on block implementation. |