Define and Configure Variant Sources and Sinks

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 control being true and visualizes the active connections.

  1. Add Variant Source and Variant Sink blocks to your model.

    These blocks enable ports that activate variant choices.

  2. 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.

  3. At the MATLAB® command prompt, specify the control variable that creates an activation condition for the variant source.

    V = Simulink.Parameter(1);
    

  4. Right-click the Variant Source block and select Block Parameters (VariantSource).

  5. In the block parameters dialog box, in the Variant control column, type V==1 next to one of the choices and 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.

  6. At the MATLAB command prompt, specify the control variable that creates an activation condition for the variant sink.

    W = Simulink.Parameter(2);
    

  7. 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.

  8. Click Apply; otherwise, your changes are not saved.

  9. Simulate the model. Simulink propagates the variant conditions to identify which model components to activate.

  10. You can visualize the conditions that activate each variant choice by selecting Display > Blocks > Variant Conditions.

  11. In the Variant Condition Legend dialog box, click through the hyperlinked variant condition annotations to observe which parts of the model each condition activates.

Related Examples

More About