Simulink.VariantBank Class
Namespace: Simulink
Group all variant parameter values in structure array in generated code
Since R2023a
Description
Use the Simulink.VariantBank
class to group variant parameters (Simulink.VariantVariable
objects) 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. 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 choice 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, which allows you to customize code placement and specify the memory section to place the parameter values in the compiled code.
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.
Creation
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 parameter banks do not support model hierarchies that contain referenced models.
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.
Extended Capabilities
Version History
Introduced in R2023a