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.

These commands return valid variant configurations for the model slexVariantManagement that satisfy the conditions specified on the variant control variables Ctrl and PlantLoc.

modelName = "slexVariantManagement";
open_system(modelName);
[vcdo,configsInfo] = Simulink.VariantManager.generateConfigurations...
 (modelName,Precondition={'Ctrl==ControllerType.Linear','PlantLoc==PlantLocation.Internal'},...
 AddPreconditionAsConstraint=true,Validity="valid");
Activating the model for the current state of the model.
Warning: The model has Simulink.VariantVariable(s) 'LUTBPs, Kc' which are not supported for generating configurations. Generated configurations will not have variations for variant parameters.
Only the active variant choice is considered for the following blocks with 'Variant activation time' set to 'update diagram'.
 slexVariantManagement/Plant
 slexVariantManagement/Plant/Internal
An update diagram operation is required to generate variant configurations.
Performing update diagram for the model.
Evaluating 12 potential combinations to generate...
Number of generated configurations: 4
Created snapshot of the model at '/tmp/Bdoc24a_2528353_1572643/tp5a19a65a/simulink_variants-ex51080552/slexVariantManagement_vmgrsnap/20240213_003252'.

The variant configuration data object vcdo 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".

[vcdo,configsInfo] = Simulink.VariantManager.generateConfigurations(modelName,...
  Precondition={'Ctrl==ControllerType.Linear','PlantLoc==PlantLocation.Internal'},...
  AddPreconditionAsConstraint=true,Validity="valid-unique");
Activating the model for the current state of the model.
Warning: The model has Simulink.VariantVariable(s) 'LUTBPs, Kc' which are not supported for generating configurations. Generated configurations will not have variations for variant parameters.
Only the active variant choice is considered for the following blocks with 'Variant activation time' set to 'update diagram'.
 slexVariantManagement/Plant
 slexVariantManagement/Plant/Internal
An update diagram operation is required to generate variant configurations.
Performing update diagram for the model.
Evaluating 12 potential combinations to generate...
Number of generated configurations: 2
Created snapshot of the model at '/tmp/Bdoc24a_2528353_1572643/tp5a19a65a/simulink_variants-ex51080552/slexVariantManagement_vmgrsnap/20240213_003259'.

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

[vcdo,configsInfo] = Simulink.VariantManager.generateConfigurations(modelName,...
  Precondition={'Ctrl==ControllerType.Linear','PlantLoc==PlantLocation.Internal'},...
  AddPreconditionAsConstraint=true,Validity="all");
Activating the model for the current state of the model.
Warning: The model has Simulink.VariantVariable(s) 'LUTBPs, Kc' which are not supported for generating configurations. Generated configurations will not have variations for variant parameters.
Only the active variant choice is considered for the following blocks with 'Variant activation time' set to 'update diagram'.
 slexVariantManagement/Plant
 slexVariantManagement/Plant/Internal
An update diagram operation is required to generate variant configurations.
Performing update diagram for the model.
Evaluating 12 potential combinations to generate...
Number of generated configurations: 4
Created snapshot of the model at '/tmp/Bdoc24a_2528353_1572643/tp5a19a65a/simulink_variants-ex51080552/slexVariantManagement_vmgrsnap/20240213_003304'.