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/Bdoc24b_2679053_916916/tp6145f984/simulink_variants-ex51080552/slexVariantManagement_vmgrsnap/20240720_181212'.

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/Bdoc24b_2679053_916916/tp6145f984/simulink_variants-ex51080552/slexVariantManagement_vmgrsnap/20240720_181217'.

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/Bdoc24b_2679053_916916/tp6145f984/simulink_variants-ex51080552/slexVariantManagement_vmgrsnap/20240720_181221'.