Main Content

Generate Variant Configurations Programmatically

This example shows how to generate variant configurations for a model programmatically.

To generate variant configurations from Variant Manager, see Generate Variant Configurations Automatically.

This command returns valid variant configurations for the model slexVariantManagement that satisfy the conditions specified on the variant control variables Ctrl and PlantLoc.

model = "slexVariantManagement";
open_system(model);
[vcdataobj,configsInfo] = Simulink.VariantManager.generateConfigurations ...
 (model, Precondition = {'Ctrl == ControllerType.Linear', 'PlantLoc == PlantLocation.Internal'}, ...
 AddPreconditionAsConstraint = true, Validity = "valid");
Activating the model for the current state of the model.
An update diagram operation is required to generate variant configurations.
Performing update diagram for the model.
Evaluating 96 potential combinations to generate...
Number of generated configurations: 16
Created snapshot of the model at '/tmp/Bdoc23a_2213998_1376426/tp81ec0541/simulink_variants-ex51080552/slexVariantManagement_vmgrsnap/20230303_082353'.

The variant configuration data object vcdataobj stores all the valid configurations. The structure array configsInfo provides information on the validity status of generated configurations.

To return only valid and functionally unique configurations, set Validity to valid-unique.

[vcdataobj,configsInfo] = Simulink.VariantManager.generateConfigurations(model,...
  Precondition = {'Ctrl == ControllerType.Linear', 'PlantLoc == PlantLocation.Internal'}, ...
  AddPreconditionAsConstraint = true, Validity = "valid-unique");
Activating the model for the current state of the model.
An update diagram operation is required to generate variant configurations.
Performing update diagram for the model.
Evaluating 96 potential combinations to generate...
Number of generated configurations: 3
Created snapshot of the model at '/tmp/Bdoc23a_2213998_1376426/tp81ec0541/simulink_variants-ex51080552/slexVariantManagement_vmgrsnap/20230303_082359'.

To return all generated configurations, including invalid configurations, set Validity to all.

[vcdataobj,configsInfo] = Simulink.VariantManager.generateConfigurations(model,...
  Precondition = {'Ctrl == ControllerType.Linear', 'PlantLoc == PlantLocation.Internal'}, ...
  AddPreconditionAsConstraint = true, Validity = "all");
Activating the model for the current state of the model.
An update diagram operation is required to generate variant configurations.
Performing update diagram for the model.
Evaluating 96 potential combinations to generate...
Number of generated configurations: 16
Created snapshot of the model at '/tmp/Bdoc23a_2213998_1376426/tp81ec0541/simulink_variants-ex51080552/slexVariantManagement_vmgrsnap/20230303_082402'.