Main Content

Simulink.VariantManager.reduceModel

Class: Simulink.VariantManager
Package: Simulink

Generate reduced model for specified variant configurations

Description

Note

This method requires Variant Manager for Simulink®.

example

Simulink.VariantManager.reduceModel(model) generates a reduced model from the input model model.

By default, the current values of variant control variables in the global workspace (base workspace or data dictionary) of the input model are used for reduction. The reduction process retains the variant configurations corresponding to these values and removes the inactive model components. The reduced artifacts are generated in a folder named ./reducedModel within the input model folder. The name of the reduced model and any reduced referenced model is the original model name suffixed with _r, by default.

Simulink.VariantManager.reduceModel(model,Name,Value) allows you to specify additional reduction options using one or more Name,Value arguments.

Input Arguments

expand all

Name of the model to be reduced, specified as a string or character vector.

Name-Value Arguments

Specify optional Name,Value arguments. Name is the argument name and Value is the corresponding value. You can specify several name and value arguments in any order as Name1,Value1,...,NameN,ValueN.

Names of variant configurations to be retained in the reduced model, specified as a string, a character vector, a cell array of strings, or a cell array of character vectors . These named variant configurations must be present in the variant configuration data object (of type Simulink.VariantConfigurationData) associated with the model.

Example: 'NamedConfigurations', 'C1'

Example: 'NamedConfigurations', {'C2'}

Data Types: char | string | cell

Variant control variables and their values that must be used for reduction, specified as a cell array containing the variable names and values.

Note

Specifying both VariableGroups and NamedConfigurations is not supported.

You can create multiple named variable groups for a model. To specify names for the variable groups, specify a struct array with the fields Name and VariantControls. Name denotes the name of the variable group, and VariantControls must be a cell array with variant control variable names and their corresponding values. For example:

 Simulink.VariantManager.reduceModel('slexVariantReducer',...
 'VariableGroups', struct('Name', 'Group1', 'VariantControls', {{'V',1,'W',[1 2]}}));

Example: 'VariableGroups', {{'V',1,'W',1},{'V',2,'W',2}}

Data Types: cell

Variables for which their full range must be considered for reduction, specified as a cell array of variant control variable names and their corresponding values. This option allows you to reduce a model for all valid values of the specified variant control variables. You must also provide a reference value for this variant control variable for which the model compiles successfully.

For example, consider a variant control variable, W, that is specified as a full-range variant control variable. W uses a reference value of 1. The reduction process considers V=1 and all valid values of W. To perform full-range analysis, Variant Reducer compiles the model once using the values {'V',1,'W',1}.

Simulink.VariantManager.reduceModel('slexVariantReducer',...
                    'VariableGroups',{'V',1},...
                    'FullRangeVariables',{'W',1});

Data Types: cell

Compilation mode, specified as 'sim' or 'codegen'. These options indicate whether the model should be compiled for simulation or code generation mode, respectively, as part of reduction. If the model contains variant blocks with the Variant control mode parameter set to sim codegen switching, you can specify the value as codegen to retain the code generation branches of the blocks in the reduced model. For the default value sim, Variant Reducer compiles and retains the simulation branches in the top-level model.

List of any dependent Simulink data dictionary files (*.sldd) and MAT-files (*.mat) outside the MATLAB® root folder to exclude during reduction, specified as a cell array of character vectors.

You can also provide wildcard characters, for example {'*.sldd'}.

Example: {'topData.sldd'}

Data Types: cell

Folder to place the reduced models and related artifacts, specified as a character vector or string. By default, the reduced models are generated in a folder named ./reducedModel within the original model folder.

Option to preserve signal attributes in the reduced model, specified as a numeric or logical 1 (true) or 0 (false). When the value is true, Variant Reducer preserves the compiled signal attributes from the original model by adding signal specification blocks at appropriate block ports in the reduced model. Compiled signal attributes include signal data types, signal dimensions, and compiled sample times.

Option to display detailed reduction steps, specified as a numeric or logical1 (true) or 0 (false). When the value is true, Variant Reducer displays details of the steps performed during model reduction.

Suffix to append to the name of the reduced model and the related artifacts, specified as a character vector.

Option to generate a summary HTML file, specified as a numeric or logical1 (true) or 0 (false). When the value is true, Variant Reducer generates an HTML file with details about the reduced model and any modifications that may be required for masks and callbacks.

Note

To generate a summary, you must have a Simulink Report Generator™ license.

Limitations

For information on modifications made to model components during reduction and limitations of the reduction process, see Considerations and Limitations for Variant Reduction.

Examples

expand all

Open the example models.

addpath(fullfile(matlabroot,'examples','simulink_variants','main'));
open_system('slexVariantReducer');
open_system('sldemo_variant_subsystems');

Reduce the sldemo_variant_subsystems model based on the variant control variable values in the base workspace.

Simulink.VariantManager.reduceModel('sldemo_variant_subsystems');

Reduce the model based on the variant control variable values in the base workspace, and place the reduced model in the specified output directory.

Simulink.VariantManager.reduceModel('sldemo_variant_subsystems', ...
'OutputFolder', 'outdir');

Reduce the model by specifying named variant configurations present in the variant configuration data object associated with the model.

Simulink.VariantManager.reduceModel('slexVariantReducer',...
'NamedConfigurations',{'config1', 'config2'});

Reduce the model by specifying variant control variables and their values.

This syntax specifies two configurations for reduction corresponding to {V==1,W==1} and {V==2,W==2}.

Simulink.VariantManager.reduceModel('slexVariantReducer',...
'VariableGroups', {{'V',1,'W',1},{'V',2,'W',2}});

Reduce the model by specifying configurations in the form of a structure of variant control variables.

This syntax specifies four configurations for reduction corresponding to {V==1,W==1}, {V==1,W==2}, {V==2,W==1}, and {V==2, W==2}.

Simulink.VariantManager.reduceModel('slexVariantReducer',...
'VariableGroups',{'V',[1 2],'W',[1 2]});

Reduce the model by specifying names for variable groups.

This syntax specifies two named variable groups, Group1 and Group2.

The reduced model has named configurations with the same name as the named variable groups, along with a suffix. In this case, the reduced model has three configurations named Group1_1, Group1_2, and Group2_1 corresponding to {V==1,W==1}, {V==1,W==2}, and {V==2,W==1}, respectively.

Simulink.VariantManager.reduceModel('slexVariantReducer',...
'VariableGroups',[struct('Name', 'Group1', 'VariantControls', {{'V',1,'W',[1 2]}}),...
struct('Name', 'Group2', 'VariantControls', {{'V',2,'W', 2}})]);

Reduce the model by specifying a variant control variable as a full-range variable.

This syntax specifies W as a full-range variant control variable with a reference value of 1. The reduction process considers four configurations corresponding to {V==1,W==1}, {V==1,W==2}, {V==1,W==3}, and {V==1,W==0}.

Simulink.VariantManager.reduceModel('slexVariantReducer',...
'VariableGroups',{'V',1},...
'FullRangeVariables',{'W',1});

Reduce the model by specifying the compilation mode as code generation.

Simulink.VariantManager.reduceModel...
('slexVariantReducer','NamedConfigurations',{'config1'},...
'CompileMode','codegen','OutputFolder','L:\Models');

Reduce the model and generate a variant reducer summary report after reduction.

This command generates the summary and saves it to the path L:\Models\variantReducerRpt.

Simulink.VariantManager.reduceModel...
('slexVariantReducer','NamedConfigurations', {'config1'},...
'GenerateSummary',true,'OutputFolder','L:\Models');

Version History

Introduced in R2016a

expand all