Route amongst multiple outputs using Variants
Simulink / Signal Routing
The Variant Sink block has one input port and one or more output ports. You can define Variant choices as blocks that are connected to the output port so that, at most, one choice is active.
Each output port is associated with a Variant control. The Variant control that
evaluates to true
, determines which output port is active.
During simulation, Simulink® connects the active choice directly to the input port of the Variant Sink block and ignores the inactive choices.
Port_1
— Input signalInput signal, specified as a scalar, vector, or matrix, to be connected to the active output port.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| Boolean
| fixed point
| enumerated
| bus
| struct
Port_1
— Output from first VariantOutput signal from the first Variant. The Variant control that
evaluates to true
, determines which output port is
active.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| Boolean
| fixed point
| enumerated
| bus
Port_N
— Output from Nth VariantOutput signal from the Nth Variant. The Variant control that evaluates
to true
, determines which output port is
active.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| Boolean
| fixed point
| enumerated
| bus
Variant control mode
— Name of the Variant control modeExpression
(default) | Label
To choose the active Variant based on the evaluation of the Variant conditions, use the
Expression
mode else select
Label
mode. When you select the Variant
control mode as Label
, the
Label mode active choice option is available. In
Label
mode, Variant control need not be created in
the global workspace. In Label
mode, the Variant control
is a string that is not evaluated and the choice used in simulation is
determined by the Label mode active choice parameter.
You can select an active Variant choice from Label mode active
choice options.
When you select Label
option, the Variant badge
indicates the change.
When you promote Label mode active choice parameter to a mask, the Variant control mode is disabled.
If the block is in Expression
mode
while promoting Label mode active
choice parameter to mask, you can change the
Variant control mode to
Label
by changing the promoted
Label mode active choice parameter
from the Mask dialog box.
If the block is in Label
mode while
promoting Label mode active choice
parameter to mask, you cannot change the Variant
control mode to Expression
mode.
For information about promoting parameters to mask, see Promote Parameter to Mask.
Port
— Number of connected input portNumber of the input port that is connected to one Variant choice upstream of the Variant Sink block. This value is read-only.
Click to add a port or
to delete an existing one.
Variant control expression
— Variant controls available in the global workspace'Variant'
(default) | boolean condition expression | Simulink.Variant
object | Simulink.Parameter
object | enumDisplays the Variant controls available in the global workspace. The
Variant control can be a Boolean condition expression or a
Simulink.Variant
object representing a Boolean
condition expression. If you want to generate code for your model, you must
define the control variables as MATLAB® variables.
To enter non-numeric Variant control values, use enumerated data. For information about using enumerated data, see Use Enumerated Data in Simulink Models
To enter a Variant name, double-click a Variant control expression cell in a new row and type in the Variant control expression. Click Apply after you edit a Variant control name. If you add or delete a Variant control without applying the changes, the previous edits on the Variant control name are lost.
Block Parameter:
VariantControls
|
Type: cell array of character vectors |
Values: Variant control that is associated with the Variant choice |
Default:
'Variant'
|
Condition (read-only)
— Condition for Variant controlsDisplays the Condition for the Variant controls that
are Simulink.Variant
objects. Create or change a Variant
condition in the Simulink.Variant
parameter dialog box or
in the global workspace.
For more information, see Create Variant Controls Programmatically and Simulink.Variant
.
Label mode active choice
— Name of Variant to use if Label control mode is selectedChoice_1
(default) | name of variant controlWhen you select the Variant control mode as
Label
, the Label mode active
choice option is available. You can select an active Variant
choice from Label mode active choice options. You can
also right-click the badge on the Variant Sink block and
select Label Mode Active Choice.
The Label mode active choice drop-down list displays all Variant
controls that are currently defined in the global workspace or a data
dictionary. Use valid MATLAB identifiers to specify Variant controls. For more information,
see Simulink.Variant
.
Label mode active choice option is not available
in Expression
mode.
To enable this parameter, select Label
mode.
Block Parameter:
LabelModeActivechoice
|
Type: character vector |
Values: Specified by the Variant control expression |
Default:
Choice_1 |
Allow zero active variant controls
— Simulate model without active Variant choiceoff
(default) | on
To simulate a model (containing a Variant block) without an active Variant choice, select the Allow zero active variant controls option. 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 Variant Sink block. The removed blocks are ignored from update diagram or simulation.
If you do not select this option, Simulink generates an error when there is no active Variant choice.
When you select this option, the Variant badge indicates the change.
Expression
option from Variant
control mode is selected.
Block Parameter:
AllowZeroVariantControls
|
Type: character vector |
Values:
'off' | 'on'
|
Default:
'off'
|
Show variant condition on block
— Annotate block portsoff
(default) | on
When you select this option, Simulink annotates each Variant control (condition expression) on the Variant Sink block ports.
Block Parameter:
ShowConditionOnBlock
|
Type: character vector |
Values:
'off' | 'on'
|
Default:
'off'
|
Analyze all choices during update diagram and generate preprocessor conditionals
— Analyze all Variant choices during update diagram or simulationoff
(default) | on
When you select this option, Simulink analyzes all Variant choices during an update diagram or
simulation. This analysis helps Simulink to maintain consistency of all Variant branches during
simulation and code generation. Simulink routes the output of the active and inactive regions to an
internal VariantMerge
block.
When you select this option, the preprocessor conditionals
(#if
) are generated in the code with ERT-based
targets.
When you select this option, the Variant badge indicates the change.
For more information, see Represent Variant Source and Sink Blocks in Generated Code (Embedded Coder)
Expression
option from
Variant control mode is
selected.
The check box is available for generating ERT targets only.
Block Parameter:
GeneratePreprocessorConditionals
|
Type: character vector |
Values:
'off' | 'on'
|
Default:
'off'
|
Data Types |
|
Direct Feedthrough |
|
Multidimensional Signals |
|
Variable-Size Signals |
|
Zero-Crossing Detection |
|
Manual Variant Sink | Manual Variant Source | Model | Simulink.Variant
| Variant Source | Variant Subsystem