Main Content

Propagate Variant Conditions from Variant Source Blocks to Conditionally Executed Subsystems

A conditionally executed subsystem is a nonvirtual subsystem that allows you to control its execution with an external signal. Enabled, Triggered, and Function-Call Subsystems are examples of conditional subsystems. The external signal that controls a conditional subsystem is called the control signal and the port through which the signal enters the block is called the control port. For more information on conditional subsystems, see Conditionally Executed Subsystems Overview.

You can use a single-input/single-output or a multi-input Variant Source block to control the execution of conditional subsystems based on the active variant conditions at the inports of the Variant Source block.

Use Variant Source Block to Control Execution of Conditional Subsystem Blocks

This example shows how to use a single-input/single-output Variant Source block to control the execution of a conditional subsystem block.

Explore the Model

Open the model slexVariantControlPorts.

The model contains a single-input/single-output Variant Source block, Variant Source1, with variant condition set as V==1. The output from Variant Source1 block is connected to the control port of the Enabled Subsystem Subsystem.

The Allow zero active variant controls parameter on the Variant Source1 block is set to on. When this option is selected and there is no active variant choice, Simulink® disables all the blocks connected to the input and output stream of the Variant Source block.

When you simulate the model after setting V=1, the condition V==1 propagates to the outport of Variant Source1 and then to the control port of Subsystem. The condition assigned to the subsystem block then propagates to the blocks named Sine2 and Out1 connected to its input and output ports. If you set V to a value other than 1, Simulink disables all the blocks connected to the inport and outport of Variant Source1.

Propagate Variant Conditions to Function-Call Subsystems

A Function-Call Subsystem block is a subsystem that another block can invoke directly during simulation. The Function-Call Subsystem block is analogous to a function in procedural programming language. For more information, see Using Function-Call Subsystems.

You can use a Variant Source block to make the Function-Call Subsystem block conditional.

The Variant Source block has condition V==1, where V is a Simulink.Parameter.

The Output function call parameter on the Variant Source block is set to on. This enables the block to output function-call signals.

The Allow zero active variant controls parameter on the Variant Source block is set to on.

When you simulate this model, the variant condition from the Variant Source block propagates to the control port of the SubA subsystem block and further propagates to the blocks connected to its inports and outports.

  • When V=1, the SubA block is active and the variant condition propagates backward and forward to the blocks connected to the input (In1) and output (Out1) ports.

  • When V~=1 (for example, V=0), SubA becomes inactive, which makes Out1 inactive. In2 remains active because it is connected to SubB, which is active.

  • If In2 is not connected to SubB, In2 becomes inactive when V~=1.

Note: If the Function-Call Subsystem is placed inside a virtual grouped subsystem, the variant condition triggering the Function-Call Subsystem must match the corresponding condition on the input of the higher level subsystem block.

Related Topics