Main Content

Analyze Variant Configurations Programmatically

This example shows how to use the Simulink.VariantConfigurationAnalysis class to analyze variant configurations programmatically.

To analyze variant configurations using Variant Manager, see Analyze Variant Configurations in Models Containing Variant Blocks.

Open the model slexVariantConfigurationAnalysis.

open_system('slexVariantConfigurationAnalysis'); 

You can provide either a list of named variant configurations or the variable groups to analyze to the Simulink.VariantConfigurationAnalysis class. The operation returns a variant configuration analysis object for the model.

varConfigObjNamedConfig = Simulink.VariantConfigurationAnalysis('slexVariantConfigurationAnalysis', ...
                           'NamedConfigurations', {'VendorACtrlLinear', ...
                           'VendorACtrlNonLinear', 'VendorACtrlFuzzy'})
varConfigObjNamedConfig = 
  VariantConfigurationAnalysis with properties:

         ModelName: 'slexVariantConfigurationAnalysis'
    Configurations: {'VendorACtrlFuzzy'  'VendorACtrlLinear'  'VendorACtrlNonLinear'}

varConfigObjVarGroup = Simulink.VariantConfigurationAnalysis('slexVariantConfigurationAnalysis',...
                          'VariableGroups', [struct('Name', 'VendorANonLinear',...
                          'VariantControls', {{'CONTROLLER', 1, 'EXTERNAL_SENSOR', 1, 'ORDER', 1, 'SATURATE', 1, 'VENDOR', 1}}),...
                           struct('Name', 'VendorALinear',...
                          'VariantControls', {{'CONTROLLER', 0, 'EXTERNAL_SENSOR', 1, 'ORDER', 1, 'SATURATE', 1, 'VENDOR', 1}})]);

You can use the variant configuration analysis object to analyze the variant configurations using different methods specified in the following steps.

Get the list of active blocks in the variant configuration VendorACtrlLinear.

activeblocks = varConfigObjNamedConfig.getActiveBlocks('VendorACtrlLinear');

Get the list of blocks that are always active across all the named variant configurations that have been analyzed.

alwaysActiveBlocks = varConfigObjNamedConfig.getAlwaysActiveBlocks();

Get the list of blocks that are active in some of the analyzed variant configurations and inactive in other configurations.

getBlockDifferences = varConfigObjNamedConfig.getBlockDifferences();

Get the list of dependent libraries for a variant configuration.

dependentLibraries = varConfigObjNamedConfig.getDependentLibraries('VendorACtrlNonLinear');

Get the list of dependent models for a variant configuration.

dependentModels = varConfigObjNamedConfig.getDependentModels('VendorACtrlFuzzy');

Get the list of blocks that are inactive in all the named variant configurations that have been analyzed.

neverActiveBlocks = varConfigObjNamedConfig.getNeverActiveBlocks();

Get the variant condition on a block in a named variant configuration.

variantCondition = varConfigObjNamedConfig.getVariantCondition('VendorACtrlNonLinear',...
'slexVariantConfigurationAnalysis/Controller/NonLinear');

Show the variant configuration analysis report for a model after analyzing it.

varConfigObjNamedConfig.showUI();

Hide the variant configuration analysis report for a model after analyzing it.

varConfigObjNamedConfig.hideUI();