Simulink.VariantBank Class
Namespace: Simulink
Group all variant parameter values in structure array in generated code
Since R2023a
Description
A variant parameter is defined as a Simulink.VariantVariable
object. Use the Simulink.VariantBank
class
to group variant parameters with the same variant conditions into a structure in generated
code, called a variant parameter bank. To add a variant parameter to a variant parameter bank,
set the Bank
property of the Simulink.VariantVariable
object to the name of the Simulink.VariantBank
object. You can use the same
variant parameter bank to group variant parameters used by models across the hierarchy. To
specify code generation properties for a variant parameter bank, use the Simulink.VariantBankCoderInfo
class.
When you generate code using Embedded Coder®, Simulink.VariantVariable
objects that are part of the same
variant parameter bank appear in a structure. This structure is named according to the
Name
property of the parameter bank object. The code contains an array of
this structure type and groups the choice values from the variant parameters based on the
variant conditions specified for the parameter bank. Each set of values becomes an element of
the structure array. The code uses a pointer variable to access the active set of values from
the structure array. The code initializes this pointer based on variant conditions in the
model_initialize
function.
Variant parameter bank switching using a pointer variable avoids copying the parameter
values into the main program memory and improves the efficiency and readability of the
generated code. Additionally, you can set code generation properties for the variant parameter
bank. You can specify separate memory sections, header, and definition files to place the
structure array and pointer in the generated code. You can also specify a type qualifier that
is applied to the declaration and definition of the array and pointer variables in the code.
See Simulink.VariantBankCoderInfo
.
For information on code generation with variant parameter banks, see Extended Capabilities.
Note
You can use variant parameter banks only with variant parameters that have the variant
activation time set to startup
.
You must have Embedded Coder to switch variant parameter banks in generated code.
You must define a variant parameter bank in the same data source (base workspace or data
dictionary) as the variant parameters grouped by it. You can add
Simulink.VariantBank
or Simulink.VariantBankCoderInfo
objects to the base workspace or the Design Data section of a data
dictionary either programmatically or from the Add menu in the Model
Explorer.
When using both Specification
and Bank
properties for a Simulink.VariantVariable
object, the specification object
must have storage class set to Auto
and it must not use symbolic
dimensions. For a variant parameter bank, use a Simulink.VariantBankCoderInfo
object to specify code generation
attributes.
Creation
Description
returns
a varparambank
= Simulink.VariantBankSimulink.VariantBank
object with default property values.
returns a varparambank
= Simulink.VariantBank(PropertyName=Value
)Simulink.VariantBank
object and sets properties using one or more
name-value arguments.
Properties
Examples
Limitations
Variant parameter banks do not support code generation for external mode operation over
tcpip
orserial
protocols. These model configuration parameter settings in the Code Generation > Interface category correspond to this mode — External mode (Simulink Coder) parameter set toOn
and Transport layer (Simulink Coder) parameter set totcpip
orserial
.Variant parameters that are part of a variant parameter bank do not support AUTOSAR code generation.
Software-in-the-loop (SIL) and processor-in-the-loop (PIL) simulations are not supported for models that use variant parameter banks.
Tips
To modify a Simulink.VariantBank
object, double-click the object to open
the Simulink.VariantBank
dialog box.
You can also create variant parameter banks from Variant Manager. See Create Variant Banks for Variant Parameters from Variant Manager.
Extended Capabilities
Version History
Introduced in R2023aSee Also
Simulink.VariantVariable
| Simulink.VariantBankCoderInfo
Topics
- Create a Simple Variant Parameter Model
- Options to Represent Variant Parameters in Generated Code (Embedded Coder)
- Group Variant Parameter Values and Conditionally Switch Active Value Sets in Generated Code (Embedded Coder)
- Generate Code for Variant Parameter Banks in Model Reference Hierarchy (Embedded Coder)
- Manage Variant Parameters Using Variant Manager