Main Content

Simulink.VariantManager.reduceModel

Generate reduced model for specified variant configurations

Description

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

By default, the current values of variant control variables in the 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 with _r appended, by default.

example

Simulink.VariantManager.reduceModel(model,Name,Value) specifies options using one or more name-value arguments in addition to the input arguments in the previous syntax. For example, to compile the model in code generation mode, set CompileMode to 'codegen'.

Note

To use this function, you must install the Variant Manager for Simulink® support package.

Examples

collapse all

Open the models slexVariantReducer and sldemo_variant_subsystems.

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');
Successfully created reduced model
'/tmp/Bdoc24b_2679053_916916/tp6145f984/simulink_variants-ex20490563/reducedModel/sldemo_variant_subsystems_r.slx'.

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','outdir1');
Successfully created reduced model
'/tmp/Bdoc24b_2679053_916916/tp6145f984/simulink_variants-ex20490563/outdir1/sldemo_variant_subsystems_r.slx'.

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'});
Successfully created reduced model
'/tmp/Bdoc24b_2679053_916916/tp6145f984/simulink_variants-ex20490563/reducedModel/slexVariantReducer_r.slx'.

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}});
Successfully created reduced model
'/tmp/Bdoc24b_2679053_916916/tp6145f984/simulink_variants-ex20490563/reducedModel/slexVariantReducer_r.slx'.

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]});
Successfully created reduced model
'/tmp/Bdoc24b_2679053_916916/tp6145f984/simulink_variants-ex20490563/reducedModel/slexVariantReducer_r.slx'.

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}})]);
Successfully created reduced model
'/tmp/Bdoc24b_2679053_916916/tp6145f984/simulink_variants-ex20490563/reducedModel/slexVariantReducer_r.slx'.

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});
Successfully created reduced model
'/tmp/Bdoc24b_2679053_916916/tp6145f984/simulink_variants-ex20490563/reducedModel/slexVariantReducer_r.slx'.

Reduce the model by excluding dependent MAT-files.

Simulink.VariantManager.reduceModel...
    ('slexVariantReducer','NamedConfigurations',{'config1'},...
     'ExcludeFiles','*.mat');
Successfully created reduced model
'/tmp/Bdoc24b_2679053_916916/tp6145f984/simulink_variants-ex20490563/reducedModel/slexVariantReducer_r.slx'.

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

Simulink.VariantManager.reduceModel...
    ('slexVariantReducer','NamedConfigurations',{'config1'},...
    'CompileMode','codegen');
Successfully created reduced model
'/tmp/Bdoc24b_2679053_916916/tp6145f984/simulink_variants-ex20490563/reducedModel/slexVariantReducer_r.slx'.

Reduce the model and generate a variant reducer summary report after reduction. This operation requires a Simulink® Report Generator™ license.

This command generates the summary and saves it to the path outdir2\variantReducerRpt.

Simulink.VariantManager.reduceModel...
    ('slexVariantReducer','NamedConfigurations',{'config1'},...
    'GenerateSummary',true,'OutputFolder','outdir2');
Successfully created reduced model
'/tmp/Bdoc24b_2679053_916916/tp6145f984/simulink_variants-ex20490563/outdir2/slexVariantReducer_r.slx'.

Input Arguments

collapse all

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

Example: 'slexVariantManagement'

Name-Value Arguments

Example: NamedConfigurations='C1'

Specify optional pairs of arguments as Name1,Value1,...,NameN,ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

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.

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 files outside the MATLAB® root folder to exclude from reduction, specified as a character vector, string array, or a cell array of character vectors or string arrays.

You can exclude:

  • Simulink model files (*.slx, *.mdl)

  • Simulink data dictionary files (*.sldd)

  • MAT-files (*.mat)

You can specify the full path of the folder or the specific files that must be excluded, which can include wildcard characters.

Example: 'components\*.slx', {'mylib.slx','myssref.slx'}, '*.sldd', 'topData.sldd'

For additional information, see Excluded Files in Model Components That Are Not Reduced.

Data Types: char | string | cell

Remove outer layer of Variant Subsystem when only one choice of the variant subsystem remains active in the reduced model, specified as a numeric or logical 1 (true) or 0 (false).

The option is enabled by default. Variant Reducer removes the outer layer of the Variant Subsystem block and moves the block that represents the active choice to the top level. The action reconnects the signal lines that were present on the removed block to the active choice.

Data Types: logical

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 logical 1 (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 logical 1 (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 for Variant Reduction and Limitations.

Version History

Introduced in R2016a

expand all