Provide Variation in Signal Source and Destination Using Manual Variant Source and Manual Variant Sink Blocks
This example shows how to use the inline variant blocks Manual Variant Source and Manual Variant Sink. The Manual Variant Source Block provides variation on the source of a signal. The block is a switch that can have two or more input ports and one output port. Each input port is associated with a variant choice. Only one input port is active during simulation. The active input port determines the active variant region. Similarly, the Manual Variant Sink block provides variation on the destination of a signal. The block can have two or more output ports and one input port. Only one output port can be active during simulation, and the blocks connected to that port determine the active variant.
Explore the Model
Open the model slexVariantManualBlocks
.
open_system('slexVariantManualBlocks');
The model has two inline variant blocks, Manual Variant Source and Manual Variant Sink. Both blocks have two variant regions at their input and output ports, respectively. The blocks indicate the currently active variant using a line that connects the input to the output.
Switch the Active Variant
To change the variant choices in the Manual Variant Source or Manual Variant Sink block, double-click the block. Instead of double-clicking the block, you can type these commands in the MATLAB® Command Window.
open_system([bdroot,'/Manual Variant Source']); open_system([bdroot,'/Manual Variant Sink']);
Access Block Parameters
To access the block parameters on a Manual Variant Source or Manual Variant Sink block, right-click the block and select Mask > Mask Parameters. You can change the number of input ports on a Manual Variant Source block or the number of output ports on a Manual Variant Sink block using the Number of Choices parameter.
Code Generation Behavior
Simulink® determines the active variant during model compilation, and the generated code contains only the active choices.