Simulink.VariantManager.reduceModel
Class: Simulink.VariantManager
Package: Simulink
Generate reduced model for specified variant configurations
Syntax
Description
Note
This method requires Variant Manager for Simulink®.
Simulink.VariantManager.reduceModel(
generates a reduced model from the input model 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 suffixed
with _r
, by default.
Simulink.VariantManager.reduceModel(
allows you to specify additional reduction options using one or more
model
,Name,Value
)Name,Value
arguments.
Input Arguments
model
— Name of model to be reduced
string | character vector
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
.
NamedConfigurations
— Names of variant configurations to be retained
string | character vector | cell array of strings | cell array of character vectors
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
VariableGroups
— Groups of variant control variables and their values
cell array
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
FullRangeVariables
— Variables for which full range must be considered for reduction
cell array
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
CompileMode
— Compilation mode
'sim'
(default) | 'codegen'
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.
ExcludeFiles
— List of files to exclude from reduction
character vector | string array | cell array of character vectors | cell array of string arrays
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
RemoveVariantSubsystemLayer
— Remove outer layer of Variant Subsystem in reduced model
true or 1
(default) | false or 0
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
OutputFolder
— Folder to place reduced model and related artifacts
string | character vector
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.
PreserveSignalAttributes
— Option to preserve signal attributes in reduced model
true
or
1
(default) | false
or 0
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.
Verbose
— Option to display detailed reduction steps
false or 0
(default) | true or 1
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.
ModelSuffix
— Suffix to append to name of reduced model
'_r'
(default) | character vector
Suffix to append to the name of the reduced model and the related artifacts, specified as a character vector.
GenerateSummary
— Option to generate summary HTML file
false or 0
(default) | true or 1
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
Reduce Variant Model Programmatically
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/Bdoc23b_2361005_2097666/tp16530eff/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/Bdoc23b_2361005_2097666/tp16530eff/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/Bdoc23b_2361005_2097666/tp16530eff/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/Bdoc23b_2361005_2097666/tp16530eff/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/Bdoc23b_2361005_2097666/tp16530eff/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/Bdoc23b_2361005_2097666/tp16530eff/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/Bdoc23b_2361005_2097666/tp16530eff/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/Bdoc23b_2361005_2097666/tp16530eff/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/Bdoc23b_2361005_2097666/tp16530eff/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/Bdoc23b_2361005_2097666/tp16530eff/simulink_variants-ex20490563/outdir2/slexVariantReducer_r.slx'.
Version History
Introduced in R2016aR2023b: ExcludeFiles
argument supports model files
The ExcludeFiles
argument now allows you to exclude
Simulink models (*.slx
, *.mdl
) outside
the MATLAB root folder during reduction.
R2023b: Change in default behavior for models with Variant Subsystem blocks
When you reduce a model that contains a VariantSubsystem block
using the reduceModel
method and if only one choice of the
Variant Subsystem remains active after reduction, then the method
removes the outer layer of the VariantSubsystem block and moves the
block that represents the active choice to the top level in the reduced model. The
RemoveVariantSubsystemLayer
argument enables this behavior
and its value is set to true
by default.
R2022b: Exclude dependent files during reduction
The ExcludeFiles
argument allows you to exclude Simulink data dictionary files (*.sldd
) and MAT-files
(*.mat
) outside the MATLAB root folder during reduction.
R2022b: Simulink Design Verifier license requirement removed
The reduceModel
method no longer requires a Simulink
Design Verifier™ license. The functionality is available as part of the Variant Manager for Simulink support package.
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other bat365 country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)