Main Content

Group Variant Parameter Values in Code Using Variant Parameter Bank

This example shows you how to group variant parameters in the generated code by adding them to the same variant parameter bank (Simulink.VariantBank).

Create a variant parameter bank.

EngineParams = Simulink.VariantBank(Name='EngineParams', Description='Engine parameters', ...
                                     VariantConditions={'V == EngType.Small', 'V == EngType.Big'});

Create a variant control variable V using the Simulink.VariantControl class. The Value property of this object allows you to select an active value for a variant parameter and the ActivationTime property allows you to specify a variant activation time. Use this variable to specify the variant condition expression for the choice values of a variant parameter.

Create two variant parameter objects K1 and K2 and associate them with the variant parameter bank EngineParams.

Use the name of the variant parameter bank to set the Bank property of a Simulink.VariantVariable object. The generated code groups the Simulink.VariantVariable objects that share the same Bank property in the same structure.

V = Simulink.VariantControl(Value=EngType.Small, ActivationTime='startup');
K1 = Simulink.VariantVariable(Choices={'V == EngType.Small', 3, 'V == EngType.Big', 6}, Bank='EngineParams');
K2 = Simulink.VariantVariable(Choices={'V == EngType.Small', [3, 6, 9], 'V == EngType.Big', [5, 10, 15]}, Bank='EngineParams');

To additionally specify code generation properties for a variant parameter bank, use the Simulink.VariantBankCoderInfo class.