Simulink® provides two blocks that you can use to visualize all possible implementations of variant choices in a model graphically. These blocks are called Variant Source and Variant Sink.
When you compile the model, Simulink
determines which variant control evaluates to
true. The active
variant determination happens early stages of compilation.Simulink then deactivates blocks that are not tied to the variant
true and visualizes the active connections.
Add Variant Source and Variant Sink blocks to your model.
These blocks enable ports that activate variant choices.
Using blocks from the Simulink Library Browser, create sources and sinks that represent variant choices. Connect choices to the input and output ports of the Variant Source and Variant Sink blocks.
At the MATLAB® command prompt, specify the control variable that creates an activation condition for the variant source.
V = Simulink.Parameter(1);
Right-click the Variant Source block and select Block Parameters (VariantSource).
In the block parameters dialog box, in the Variant
control column, type
V==1 next to one of the
V==2 next to the other. Click
Apply; otherwise, your changes are not saved.
Simulink verifies that only one variant is active for simulation. When the control condition does not activate a variant, Simulink uses the default variant for simulation.
At the MATLAB command prompt, specify the control variable that creates an activation condition for the variant sink.
W = Simulink.Parameter(2);
Double-click the Variant Sink. In the block parameters dialog
box, in the Variant control column, type
W==1 next to one of the choices and
W==2 next to the other.
Click Apply; otherwise, your changes are not saved.
Simulate the model. Simulink propagates the variant conditions to identify which model components to activate.
You can visualize the conditions that activate each variant choice by selecting Display > Blocks > Variant Conditions.
In the Variant Condition Legend dialog box, click through the hyperlinked variant condition annotations to observe which parts of the model each condition activates.