Variant Subsystem
Template subsystem containing Subsystem blocks as variant choices
Libraries:
Simulink /
Ports & Subsystems
HDL Coder /
Ports & Subsystems
Alternative Configurations of Variant Subsystem Block:
Variant Model | Variant Assembly Subsystem
Description
The Variant Subsystem block enables you to include multiple implementations of a component in a separate hierarchy.
For example, suppose you want to simulate a model that represents a vehicle with three possible engine configurations: 2-cylinder gas, 4-cylinder gas, and 8-cylinder gas. You could implement each engine model as a separate subsystem inside the Variant Subsystem block and then switch between the subsystems based on the Types of Variant Control Modes in Variant Blocks you select. For more information, see Introduction to Variant Controls.
Note
Only one implementation of a Variant Subsystem block is active during simulation.
The Variant Subsystem block is a template preconfigured to contain two or more blocks to use as variant choices. These choices represent multiple implementations of a system. Only one child block is active during model execution. The active child block is referred to as the active variant.
Each variant choice inside the Variant Subsystem block is associated with a Variant control mode and a Variant activation time. The variant control mode determines how to select the active variant. The variant activation time determines a time to activate the choices and to decide whether to include only the active choice or both active and inactive choices in the generated code.
A Variant Subsystem block can contain a mixture of Subsystem blocks, Model blocks, or Subsystem Reference blocks as variant choices. A Variant Subsystem block with only Model blocks as choices is called a Variant Model block. For more information, see Implement Variations in Separate Hierarchy Using Variant Subsystems. A Variant Subsystem block with Model or Subsystem Reference blocks as choices that can be added or removed only from external files and not within the block is called a Variant Assembly Subsystem block.
Apart from the variant choices, you can include Inport, control port (Enable, Trigger, Reset, and Function-Call Subsystem), Outport, or Connection Port (Simscape) blocks inside a Variant Subsystem block. There are no drawn connections between the blocks that are inside the Variant Subsystem blocks. The software automatically wires the active variant to the Inport and Outport blocks of the Variant Subsystem during model compilation. The blocks representing variant choices can have input and output ports that differ in number from the input and output ports in the parent Variant Subsystem block. For more information, see Map Input and Output Ports of Variant Choices in Variant Subsystem.
When you load a model with a Variant Subsystem block that has variant
choices stored in subsystem files, by default, only the active choice is loaded to
optimize the loading time for models. However, if you initialize a model
programmatically using the find_system
,
get_param
, or set_param
function, inactive
choices might get loaded.
Using Variant Subsystem block allows you to:
Mix Subsystem, Model, and Subsystem Reference blocks as variant choices.
Model components that do not have similar interface. You can have different numbers of inports and outports for multiple variant choices inside a Variant Subsystem. However, the conditions listed in Map Input and Output Ports of Variant Choices in Variant Subsystem must be met.
Establish a hierarchical block diagram, where the Variant Subsystem block is on one layer and the variant choices are on another layer.
Keeps functionally related blocks together.
Reduce the complexity of your model.
During model compilation, the software eliminates inactive blocks throughout the model, depending on the variant activation time you select.
The color and icon of the variant badge on the block icon changes depending on the values of the Variant activation time, Variant control mode, and Propagate conditions outside of variant subsystem parameters set on the block. For more information, see Variant Badges.
Examples
Implement Variations in Separate Hierarchy Using Variant Subsystems
Learn basic functionality of variant subsystems.
Ports
During simulation, the software disables the inactive ports in a Variant Subsystem block.
Input
Each Subsystem, Model, or Subsystem Reference block contained within a Variant Subsystem represents one variant choice. The variant choices can contain Inport, control port (Enable, Trigger, Reset, and Function-Call Subsystem), or Connection Port (Simscape) blocks at its input. The variant choices can have input ports that differ in number from the input ports in the parent Variant Subsystem block. However, the conditions described in Map Input and Output Ports of Variant Choices in Variant Subsystem must be met.
Output
Each Subsystem, Model, or Subsystem Reference block contained within a Variant Subsystem represents one variant choice. The variant choices can contain Outport or Connection Port (Simscape) blocks at its output. The variant choices can have output ports that differ in number from the output ports in the parent Variant Subsystem block. However, the conditions described in Map Input and Output Ports of Variant Choices in Variant Subsystem must be met.
The unconnected output ports (inactive output ports) of a Variant Subsystem block output a ground value. To output a value other than ground, select the Specify output when source is unconnected parameter of the Outport block and specify a value.
Map Input and Output Ports of Variant Choices in Variant Subsystem
A Variant Subsystem block allows you to use a combination of Subsystem, Model, or Subsystem Reference blocks as variant choices. The inputs that the Variant Subsystem block receives from upstream model components map to the input and output ports of the variant choices.
The blocks that represent variant choices can have input and output ports that differ in number from the input and output ports in the parent Variant Subsystem block. However, the following conditions must be met:
The variant choices must have same set of input ports as the Variant Subsystem container block or it must be a subset of ports on the container block.
The variant choices must have same set of output ports as the Variant Subsystem container block or it must be a subset of ports on the container block.
If the Variant Subsystem container block has control ports:
The type of control port blocks in all the variant choices must be same as the Variant Subsystem block. For example, you cannot use Enabled Subsystem and Function-Call Subsystem blocks as choices within a Variant Subsystem block.
The control port on the Variant Subsystem block and the corresponding control ports on its variant choices must have the same name. For example, if the name of the control port on the Variant Subsystem block is
fcn
, then the name of the corresponding control ports on all its variant choices must also befcn
.
Parameters
To access these parameters, right-click the variant badge on the block icon and select Block Parameters. For more information, see Variant Badges.
The variant control that determines the active variant choice can be any of these types.
expression
— The software chooses the active variant based on the evaluation of the variant conditions. When a condition expression evaluates totrue
, the corresponding variant choice becomes active. When a condition expression evaluates tofalse
, the corresponding variant choice becomes inactive. See Switch Between Choices Using Condition Expressions in Variant Blocks.label
— The software chooses the active variant based on the name of the variant. The variant control is a string and does not require you to create any variable in any workspaces. See Switch Between Choices Using Labels in Variant Blocks.sim codegen switching
— Automatically switch between the variants for simulation and code generation workflows without creating any workspace variable. When you simulate a model, the software automatically chooses thesim
branch as the active choice. Similarly, when you do a software-in-the-loop (SIL) or processor-In-Loop (PIL) simulation, generate code, or use external mode, the software automatically chooses thecodegen
branch. See Switch Between Choices for Simulation and Code Generation Workflows Without Using Control Variables in Variant Blocks.
For more information on variant control modes, see Introduction to Variant Controls. For a comparison between different types of variant control modes, see Compare Different Types of Variant Control Modes in Variant Blocks.
Dependencies
The availability of different variant activation times depends on the type of the Variant control mode that you specify. The Variant activation time parameter determines the time when the software sets the active choice. The parameter also determines which variability to include in the generated code. This table explains the variant activation time supported by each variant control mode.
Variant activation time | |||||
---|---|---|---|---|---|
Variant control mode | update diagram | update diagram analyze all
choices | code compile | startup | runtime (Variant
Subsystem block only) |
expression | ✓ | ✓ | ✓ | ✓ | ✓ |
label | ✓ | x | x | x | x |
sim codegen switching | ✓ | ✓ | x | x | x |
Programmatic Use
Block Parameter:
VariantControlMode
|
Type: character vector |
Values:
'expression' | 'label' | 'sim
codegen switching' |
Default:
'expression'
|
This parameter determines which variability to include in the simulation and code generation workflows. For more information, see Activate Variant During Different Stages of Simulation and Code Generation Workflow.
update diagram
— When you execute the model, only the active choice is included in the simulation and the code generation workflow. Generated code contains only the active choice.update diagram analyze all choices
— When you execute the model, both active and inactive choices are analyzed for consistency across the model. However, only the active choice is included in the simulation and the code generation workflow. Generated code contains only the active choice.code compile
— When you execute the model, both active and inactive choices are analyzed for consistency across the model, and all choices are included in the simulation and the code generation workflow. Generated code contains both the active and inactive choices enclosed in the preprocessor conditionals#if
and#elif
. However, the executable built from the generated code contains only active choice.startup
— When you execute the model, both active and inactive choices are analyzed for consistency across the model, and all choices are included in the simulation and the code generation workflow. With this option, you can improve the speed of iterative simulations using fast restart. For more information, see Run Iterative Simulations Without Recompiling Model for Variant Systems Using Fast Restart. Code generated from the model contains both the active and inactive choices that are enclosed in regularif
conditions. The executable built from the generated code also contains both active and inactive choices.runtime
— When you execute the model, the active variant can switch during simulation or execution of the generated code by using the Parameter Writer block. Place a Parameter Writer block inside a conditionally executed subsystem or in an Initialize Function block, a Reinitialize Function block, or a Reset Function block. For more information on the blocks, see Event Functions. You can use the Parameter Writer block to write to block parameters, model workspace variables, and base workspace variables. Multiple variant control variables are not supported forruntime
activation time. All modeling patterns supported by the Parameter Writer block are valid for run-time activation. For more information, see Common Uses of Parameter Writer Block.When you set the Variant activation time parameter of the Variant Subsystem block to
runtime
, the color of the inactive variant choices does not fade. In this case, the setting of the Variant Fading option in the Information Overlays menu on the Debug tab of the Simulink Editor is ignored.inherit from Simulink.VariantControl
— When you execute the model, the block inherits the activation time from its variant control variables of typeSimulink.VariantControl
. If a variant block has multiple variant control variables of typeSimulink.VariantControl
, then all those variables must have the same activation time.
The table compares the different variant activation times based on conditional code, variant switching, handling of states, and fast restart support.
update diagram or update diagram
analyze all choices | code compile | startup | runtime | |
---|---|---|---|---|
Generated conditional code | Inactive conditional code is not available. | Conditional code is present inside preprocessor macros. The inactive choice code is eliminated when generated code is compiled. | Conditional code is generated as part of an
if-elseif-else statement. The variant control
variable value cannot be modified during execution. | Conditional code is generated as part of an
if-elseif-else statement. The variant control
variable value can be modified during execution. |
Variant switching during simulation or code execution | Not supported. | Not supported. | Supported at startup (before simulation start at t = 0). | Supported. The active variants are switched by changing the variant control variable using the Parameter Writer block. |
Explicit setting of held or reset option for states | Not supported. States are reset for inactive blocks. | Not supported. States are reset for inactive blocks | States cannot be changed during simulation. In the generated code, if you attempt to change the variant, states are in held state. | States are held by default. Reset states explicitly through State Writer blocks. Read blocks with states by using the State Reader block and transfer to another choice by using the State Writer block. |
Executable size | Smaller size. Code is not generated for the inactive variant. | Smaller size. The inactive variant code is removed during compilation. | Comparatively larger size. Both active and inactive variant code is available for startup switching. | Comparatively larger size. Both active and inactive variant code is available for run-time switching. |
Fast restart support | Not supported. | Not supported. | Supported. | Supported. |
Dependencies
The availability of different variant activation times depends on the type of the variant control mode that you specify. The Variant activation time parameter determines when the software sets the active choice. The parameter also determines which variability to include in the generated code. This table explains the variant activation time supported by each variant control mode.
Variant activation time Variant control mode update diagram
update diagram analyze all choices
code compile
startup
runtime
expression
✓ ✓ ✓ ✓ ✓ label
✓ x x x x sim codegen switching
✓ ✓ x x x To enable switching of active variant choice of the Variant Subsystem block using the
runtime
activation time, you must use the Parameter Writer block. Set the Destination parameter of the Parameter Writer block based on the location of your variant control variable and select Validate parameter :Block parameter
— Control variable is a mask parameter in a subsystem.Model workspace variable
— Control variable is located in the model workspace.Base workspace variable
— Control variable is located in the base workspace or a data dictionary.
For example, you can create a mask parameter
V
in a subsystem and use it in a variant condition expression for a variant control. The Parameter Writer block writes to the value ofV
in the variant control condition.
Programmatic Use
Block Parameter:
VariantActivationTime
|
Type: character vector |
Values:
'update diagram' | 'update diagram analyze all
choices' | 'code compile' |
'startup' | 'runtime' |
Default:
'update diagram'
|
When you specify a variable of type listed in Types of Variant Control Variables (Operands) in Variant Blocks, the
software generates variant control expressions for the variant choices of the
Variant Assembly Subsystem block. The Variant
control variable that you specify here is on the left side and
the members of the Variant enumeration choice are on the
right side of the generated expressions. Both the sides are related by
==
.
The variant control variable acts as a switch to change the active variant
choice. You specify a value for a variant control variable and run the
simulation. During simulation, the software evaluates the variant control
expressions to determine the active variant choice. When an expression evaluates
to true
, the corresponding variant choice is set active. To
change the active variant, change the value of the variant control variable such
that the corresponding variant control expression evaluates to
true
turns active.
Dependencies
This parameter is available only in Variant Assembly
Subsystem block. To enable this parameter, set Variant
control mode to expression
.
Programmatic Use
Block Parameter:
VariantControlVariable
|
Type: character vector |
Values:
Simulink.VariantControl object, scalar variable,
Simulink.Parameter object,
struct |
Default:
'' |
To add Model or Subsystem Reference blocks as
variant choices to a Variant Assembly Subsystem block, specify an
enumeration class name that contains the corresponding model or subsystem
filenames as its members. You can then validate the enumeration class using the
Refresh button in the Variant choices table. On a
successful validation, the members of the enumeration class are added as variant
choices to the Variant Assembly Subsystem block. Each choice has
a variant control expression with Variant control
variable on its left side and the members of the
Variant choices enumeration that you specify here on
its right side. Both the sides of the expression are related by
==
. The newly added variant choices and their
corresponding control expressions are displayed in the Variant
choices table.
To remove variant choices from a Variant Assembly Subsystem block, remove the corresponding members from the enumeration class that you specify here. You cannot manage the variant choices from inside the Variant Assembly Subsystem block.
The enumeration class that you specify must be on the search path of your
current MATLAB® session. For information on how to add files or folders to the
search path, see addpath
.
For more information on how to add choices using the Variant choices enumeration parameter, see Add or Remove Variant Choices of Variant Assembly Subsystem Blocks Using External Files.
Dependencies
This parameter is available only in Variant Assembly
Subsystem block. To enable this parameter, set Variant
control mode to expression
.
Programmatic Use
Block Parameter:
VariantChoicesEnumeration
|
Type: character vector |
Values: enumeration class defined using
classdef or
Simulink.defineIntEnumType |
Default:
'' |
To add Model or Subsystem Reference blocks as variant choices to a Variant Assembly Subsystem block, specify the corresponding model or subsystem filenames. The filenames must be specified as a MATLAB expression that returns a one-dimensional cell array of character vectors when evaluated or an array of strings. You can then validate the expression using the Refresh button in the Variant choices table. On a successful validation, the blocks that correspond to the specified files are added as variant choices to the Variant Assembly Subsystem block. For each choice, a variant control label is generated. The name of the variant control label is same as the name of the choice. The newly added variant choices and their corresponding control labels are displayed in the Variant choices table.
To remove variant choices from a Variant Assembly Subsystem block, modify the expression specified in this parameter. You cannot manage the variant choices of a Variant Assembly Subsystem block from inside the block.
The MATLAB expression that you specify must contain either of these:
Model or subsystem filenames that are on the search path of your current MATLAB session. For example, if you specify
{'model1.slx', 'subsystemRef1.slx'}
as a specifier, the blocks that correspond to themodel1.slx
andsubsystemRef1.slx
files are added as variant choices of the Variant Assembly Subsystem block.File name patterns that match the model or subsystem filenames on the MATLAB path. The paths in the pattern can be absolute or relative to the parent folder of the model that contains the Variant Assembly Subsystem block. For example, if you specify
{'folder_1/*.slx', 'folder_2/*.slx'}
as a specifier, the software passes the character vectorsfolder_1/*
andfolder2/*
to thedir
function. The function then returns the model and the subsystem files that are located inside thefolder1
andfolder2
folders. The blocks that correspond to the returned files are added as variant choices of the Variant Assembly Subsystem block.
For information on how to add files or folders to the search
path, see addpath
.
For more information on how to specify choices in the Variant choices specifier parameter, see Add or Remove Variant Choices of Variant Assembly Subsystem Blocks Using External Files.
Dependencies
This parameter is available only in Variant Assembly
Subsystem block. To enable this parameter, set Variant
control mode to label
.
Programmatic Use
Parameter:
VariantChoicesSpecifier
|
Type: character vector |
Value: Any MATLAB expression that evaluates to a one-dimensional cell array of filenames or filename patterns. |
Default:
'' |
The table has a row for each variant choice contained in the variant subsystem. If there are no variant choices, the table is empty.
You can use buttons to the left of the Variant choices table to modify the elements in the table.
To... | Click... |
---|---|
Create and add a new subsystem choice: Create a new Subsystem block as a variant choice and add an entry for the new choice in the table. | ![]() |
Create and add a new model variant choice: Create a new Model block as a variant choice and add an entry for the new choice in the table. | ![]() |
Delete selected variant choices: Delete variant choices permanently. |
|
Create/Edit selected variant
object: Create or edit a
Note For a model that uses the base workspace, this
operation creates the
| ![]() |
Open selected variant choice block: Open the Subsystem block for the selected row. | ![]() |
Refresh dialog information from Variant Subsystem contents: Update the Variant choices table according to the variant choices and values of the variant control in the global workspace. | ![]() |
Dependencies
The Variant Assembly Subsystem block allows you to only open the selected variant choice and refresh the list of variant choices using the buttons in this section. To add new variant choices to the Variant Assembly Subsystem block, see Add or Remove Variant Choices of Variant Assembly Subsystem Blocks Using External Files.
This parameter is read-only.
This parameter displays the
name of the choices. Each choice has a variant control in the form of labels,
expressions, or switches. For Variant Assembly Subsystem in the
label
mode, no separate variant control is
available. The name of the choice is used as a variant control to set the active
choice.
A name for a choice, specified as a string.
Dependencies
To enable this parameter, set Variant control mode to
label
.
Programmatic Use
To set the block parameter value programmatically, use
the set_param
function.
To get the block parameter value
programmatically, use the get_param
function.
Parameter: | VariantControl |
Values: | variant control that is associated with the variant choice |
Data Types: | char |
Example: set_param(gcb, 'VariantControl', 'V == 3')
,
where gcb
is the variant choice of the Variant
Subsystem block.
Example: get_param(gcb, 'VariantControl')
, where
gcb
is the variant choice of the Variant
Subsystem block.
Specify (sim)
to activate the corresponding variant choice
during simulation. Specify (codegen)
to activate the
corresponding variant choice while performing code generation workflows such as
SIL, PIL, external mode, and so on.
Dependencies
To enable this parameter, set Variant control mode to
sim codegen switching
.
Programmatic Use
To set the block parameter value programmatically, use
the set_param
function.
To get the block parameter value
programmatically, use the get_param
function.
Parameter: | VariantControl |
Values: | variant control that is associated with the variant choice |
Data Types: | char |
Example: set_param(gcb, 'VariantControl', '(sim)')
,
where gcb
is the variant choice of the Variant
Subsystem block.
Example: get_param(gcb, 'VariantControl')
, where
gcb
is the variant choice of the Variant
Subsystem block.
Specify the condition expression to determine the active choice. When a condition
expression evaluates to true
, the software activates the
corresponding variant choice. When a condition expression evaluates to
false
, the software deactivates the corresponding variant
choice.
The variant controls can be:
Boolean condition expression for rapid prototyping. For example,
A == 1
,A ~= B
,A && B == 1
, and so on.A
Simulink.VariantExpression
object that contains a condition expression for condition reuse. See Simulink.VariantExpression Objects for Variant Condition Reuse of Variant Blocks.Default Variant Choice if none of the choices evaluates to
true
.
Here, A
and B
are operands called
as variant control variables. ==
,
~=
, and &&
are operators in the
condition expression. The condition expression can contain one or more such variant
control variables and operators. For information on supported types and storage location
of variant control variables, see Types of Variant Control Variables (Operands) in Variant Blocks and Storage Locations for Variant Control Variables (Operands) in Variant Blocks. For information
on operators, see Types of Operators in Variant Blocks for Different Activation Times.
For more information, see Switch Between Choices Using Condition Expressions in Variant Blocks.
In Variant Assembly Subsystem block, this parameter is a list of
auto-generated boolean expressions with Variant control variable on
the left-hand side and the members of the Variant enumeration
choice are on the right-hand side of the expressions. Both the sides of
the expressions are connected with ==
. This parameter is
read-only.
Programmatic Use
To set the block parameter value programmatically, use
the set_param
function.
To get the block parameter value
programmatically, use the get_param
function.
Variant Subsystem block:
Parameter: | VariantControl |
Values: | variant control that is associated with the variant choice |
Data Types: | char |
Example: set_param(gcb, 'VariantControl', 'V == 3')
, where
gcb
is the variant choice of the Variant
Subsystem block.
Example: get_param(gcb, 'VariantControl')
, where
gcb
is the variant choice of the Variant
Subsystem block.
Variant Source and Variant Sink blocks:
Parameter: | VariantControls |
Values: | variant controls that are associated with variant choices |
Data Types: | char |
Example: set_param(gcb, 'VariantControls', {'A == 1','A ==
2'})
, where gcb
is the Variant
Sink or Variant Source block.
Example: get_param(gcb, 'VariantControls')
, where
gcb
is the Variant Sink or Variant
Source block.
This parameter is read-only.
This parameter displays the condition expression specified as
Simulink.VariantExpression
object. To change or edit the condition
expression, use the Simulink.VariantExpression
parameter dialog box
that appears when you double-click the object in the workspace.
Note
The operands that you specify in a condition expression of type
Simulink.VariantExpression
must be defined in the base
workspace or a data dictionary. Specifying operands that are defined in the mask
or model workspace is not supported.
This list contains the labels of all the variant choices. To set an active choice, select a label from the list. The corresponding choice becomes active. Alternatively, to change the active choice in label mode, you can follow the approaches described in Set Active Choices Using Variant Control Labels.
Dependencies
To enable this parameter, set Variant control mode to
label
.
Programmatic Use
Parameter:
LabelModeActiveChoice
|
Type: character vector |
Value: If no label mode active choice is specified, the value is empty. If a label mode active choice is specified, the value is the variant control label for the active choice. |
Default: '' |
off
— Simulink® generates an error when there is no active variant choice.on
— When you select this option, Simulink adds a nonmodifiable variant choice entry to the Variant choices table with its variant control set to(default)
. This entry does not appear as a visible variant choice in the Variant Subsystem block. During simulation, if there is no active variant choice, Simulink disconnects the variant choices of the Variant Subsystem block, thus removing the variant regions completely from the model. The inactive outports of the subsystem output zero. To output a value other than zero, select the Specify output when source is unconnected parameter of the Outport block and specify a value of your choice.
For more information, see Manage Variant Components to Pass Specified Values from Inactive Variant Subsystems with No Active Choice (Simulink Coder).
Dependencies
This parameter is available only if there are no
default
variant choices in the Variant
Subsystem and if you set Variant control
mode to expression
.
Programmatic Use
Parameter:
EmptyChoice
|
Type: character vector |
Value:
'off' | 'on' |
Default:
'off' |
off
— Simulink generates an error when there is no active variant choice.on
— When you select this option, Simulink adds a nonmodifiable variant choice entry to the Variant choices table with its variant control set to(default)
. This entry does not appear as a visible variant choice in the Variant Subsystem block. During simulation, if there is no active variant choice, Simulink bypasses the variant choices of the Variant Subsystem block. Only the input and output ports remain active, and the input port pass values directly to the output ports.For values to be mapped from input ports to output ports when no choice is active, the Variant Subsystem block must have:
Only data ports, with no other types of input and output ports
An equal number of data input and output ports
Input and output ports that exactly match the ports of variant choices
For more information, see Manage Variant Components to Pass Specified Values from Inactive Variant Subsystems with No Active Choice (Simulink Coder).
Dependencies
This parameter is available only if there are no
default
variant choices in the Variant
Subsystem and if you set Variant control
mode to expression
.
Programmatic Use
Parameter:
PassThrough
|
Type: character vector |
Value:
'off' | 'on' |
Default:
'off' |
When you select the Propagate conditions outside of variant subsystem parameter, the software propagates the variant condition of the underlying blocks to the Variant Subsystem container block so the subsystem can adapt its interface to the state of the underlying blocks. Ports that are mapped to the ports on the active choice becomes active. Ports that are not mapped to the ports on the inactive choice becomes inactive. Selecting this option ensures that the components outside of the Variant Subsystem are aware of the active and inactive state of blocks within the Variant Subsystem block. For more information, see Propagate Variant Conditions to Define Variant Regions Outside Variant Subsystems to Promote Consistency and Reduce Errors and Propagate Variant Conditions to Control Execution of Conditional Subsystems
Variant conditions do not propagate outside a Variant Subsystem block if all variant choices within the block have the same interface.
Programmatic Use
Parameter:
PropagateVariantConditions
|
Type: character vector |
Value:
'off' | 'on' |
Default:
'off' |
Specify whether to make the interface of a variant subsystem flexible.
on
— Simulate with variant choices that have input and output ports that differ in number from the input and output ports of the Variant Subsystem block.off
— When you simulate with this option, if there is inconsistency in the interface, the software will generate errors with fix-it actions to match the ports of the variant choices to the Variant Subsystem block.
Programmatic Use
Parameter:
AllowFlexibleInterface
|
Type: character vector |
Value:
'off' | 'on' |
Default:
'on' |
Block Characteristics
Alternative Configurations
The Variant Model block is a template that contains Model blocks.
Libraries:
Simulink /
Ports & Subsystems
A Variant Assembly Subsystem block enables you to add or remove its variant choices from external sources without modifying the model. A Variant Assembly Subsystem block can contain Model blocks, Subsystem Reference blocks, or both as its variant choices. You specify the source of variant choices in the block parameter dialog box once and then modify the source to add or remove the variant choices from the block. You can also move or resize the Model or Subsystem Reference blocks inside the Variant Assembly Subsystem block. Unlike the Variant Subsystem block, you cannot manage the variant choices from inside the Variant Assembly Subsystem block. Any modifications to add or remove variant choices must be made through the specified source. The attempts to modify variant choices, such as adding or deleting choices, renaming them, or changing the variant controls associated with them, by alternative methods result in an error. For more information, see Add or Remove Variant Choices of Variant Assembly Subsystem Blocks Using External Files.
To convert a Variant Subsystem block to a Variant Assembly Subsystem block, follow the steps in Convert Variant Subsystem to Variant Assembly Subsystem.
Extended Capabilities
Actual data type or capability support depends on block implementation.
HDL Coder™ provides additional configuration options that affect HDL implementation and synthesized logic. Actual data type or capability support depends on block implementation.
Architecture | Description |
---|---|
Module (default) | Generate code for the subsystem and the blocks within the subsystem. HDL Coder generates code for all the variant choices. |
BlackBox | Generate a black-box interface. That is, the generated HDL code includes only the input/output port definitions for the subsystem. In this way, you can use a subsystem in your model to generate an interface to existing manually written HDL code. The black-box interface generated for subsystems is similar to the interface generated for Model blocks, but without generation of clock signals. |
| Remove the subsystem from the generated code. You can use the subsystem in simulation but treat it as a “no-op” in the HDL code. |
For the BlackBox
architecture, you
can customize port names and set attributes of the external component
interface. See Customize Black Box or HDL Cosimulation Interface (HDL Coder).
General | |
---|---|
AdaptivePipelining | Automatic pipeline insertion based on the synthesis tool, target frequency, and
multiplier word-lengths. The default is |
BalanceDelays | Detects introduction of new delays along one path and inserts
matching delays on the other paths. The default is |
ClockRatePipelining | Insert pipeline registers at a faster clock rate instead of the slower data rate. The
default is |
ConstrainedOutputPipeline | Number of registers to place at
the outputs by moving existing delays within your design. Distributed
pipelining does not redistribute these registers. The default is
|
DistributedPipelining | Pipeline register distribution,
or register retiming. The default is |
DSPStyle | Synthesis attributes for multiplier mapping. The default is |
FlattenHierarchy | Remove subsystem hierarchy from generated HDL code. The default
is |
InputPipeline | Number of input pipeline stages
to insert in the generated code. Distributed pipelining and constrained
output pipelining can move these registers. The default is
|
OutputPipeline | Number of output pipeline stages
to insert in the generated code. Distributed pipelining and constrained
output pipelining can move these registers. The default is
|
SharingFactor | Number of functionally equivalent resources to map to a single shared resource. The default is 0. See also Resource Sharing (HDL Coder). |
StreamingFactor | Number of parallel data paths, or vectors, that are time multiplexed to transform into serial, scalar data paths. The default is 0, which implements fully parallel data paths. See also Streaming (HDL Coder). |
Target Specification
This block cannot be the DUT, so the block property settings in the Target Specification tab are ignored.
The Variant Subsystem cannot be a design-under-test (DUT).
Variant activation time parameter must be set to
update diagram
,update diagram analyze all choices
, orstartup
.For the Outport block of the Variant Subsystem, Specify output when source is unconnected parameter must be disabled.
Actual data type or capability support depends on block implementation.
Version History
Introduced in R2010bThe callbacks LoadFcn
, ContinueFcn
,
InitFcn
, ModelCloseFcn
,
PauseFcn
, PostSaveFcn
,
PreSaveFcn
, StartFcn
, and
StopFcn
do not execute for inactive variant choices in Variant Subsystem blocks with the
update diagram
activation time and for commented
blocks. This suppression reduces computational overhead and prevents unnecessary
diagnostic messages from the blocks that do not affect the current model iteration.
However, these callbacks are not suppressed for blocks within models or subsystem
files inside a commented or an inactive Model block or Subsystem Reference block. Also, the mask initialization and mask
parameter callbacks are not suppressed. For the list of applicable callbacks, see
Author Mask Initialization and Callbacks and Mask Parameters.
The Allow zero active variant controls parameter is now renamed to Built-in empty choice. This new parameter maintains the previous functionality to remove the variant components and output zero when no variant choice is active.
Use the Built-in passthrough choice parameter to bypass variant region and assign input values to the output ports when no variant choice is active.
Starting in R2024b, use the runtime
variant activation time in
a Variant Subsystem block to change the active variant during
simulation or code generation by using the Parameter Writer block.
You can model all scenarios where the Parameter Writer block can
write to the variant control variable in the global workspace, mask workspace, or
model workspace.
Simulink provides options to add missing ports and delete unused ports in Variant Subsystem and Variant Assembly Subsystem blocks to match the ports of the underlying variant choices. During simulation, if Simulink encounters a port mismatch between a Variant Subsystem or Variant Assembly Subsystem block and its variant choices, the resulting error message provides the option of adding missing ports and deleting unused ports to resolve the issue.
You can use adapted rate-based model blocks as variant choices in a Variant Subsystem block. When you add adapted rate-based models as variant choices, the inports in the variant subsystem are matched to the port names of the respective rate-based models.
You can access the mask of the active variant choice of the Variant Subsystem directly without having to navigate inside the Variant Subsystem block.
If the Variant Subsystem block is unmasked, double-clicking on the block opens the mask of its active choice. Clicking on the Look under mask badge or selecting the corresponding option from the context menu of the Variant Subsystem block takes you directly inside the active choice.
If the Variant Subsystem block is masked and the active choice also has a mask, then double-clicking on the block opens the Variant Subsystem mask.
If the Variant Subsystem block is unmasked and its active choice is masked, then double-clicking on the Look under mask badge takes you to the variant layer. You can see similar behavior in a masked Variant Subsystem block with an unmasked active choice.
When you click on the Look under mask badge of a linked
Variant Subsystem block with its active choice as a linked and
masked Model Reference block, the Model Reference
opens in a separate editor. Additionally, you must perform
set_param
operations on the mask parameters of the active
choice block on the active choice, and not on the Variant Subsystem
block.
Promotion of the mask of the active choice is limited to its immediate parent. Nested Variant Subsystem mask promotion is not supported.
You can specify Variant choices specifier as an array of strings in Variant Assembly Subsystem block.
Simulink promotes the content preview of the active choice of the Variant Subsystem block automatically. When the active choice is a Model Reference that is not loaded, and when the active choice is a Stateflow chart, the Variant Subsystem is shown as the content preview.
You can navigate directly inside the active variant by double clicking on the
Variant Subsystem block. When you select Open in New
Tab or Open in New Window from the context menu,
the active choice is opened in a new tab or a new window. You can also use the
open_system
function to access the variant layer and the
active choice.
open_system(vssBlock) open_system(vssBlock,'ActiveChoice','window')
OpenFcn
callback, double-clicking on the Variant
Subsystem block does not execute that callback. Additionally,
double-clicking on the Variant Subsystem does not navigate into the
active choice if the active choice is a referenced model that is not loaded.Simulink automatically displays the mask icon of the active variant block on the parent Variant Subsystem. Prior to R2021a, you had to provide icon drawing commands on the mask of the Variant Subsystem to display the mask icon of the underlying active variant block.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: United States.
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)