Simulink.VariantManager.reduceModel
Generate reduced model for specified variant configurations
Syntax
Description
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 with
_r
appended, by default.
Simulink.VariantManager.reduceModel(
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 model
,Name,Value
)CompileMode
to
'codegen'
.
Note
To use this function, you must install the Variant Manager for Simulink® support package.
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/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
model
— Name of model to be reduced
string | character vector
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.
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.
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
logical 1
(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
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 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 Simulink.VariantManager.reduceModel
function and if only
one choice of the Variant Subsystem block remains active after
reduction, then the function removes the outer layer of the Variant
Subsystem 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 Simulink.VariantManager.reduceModel
function no longer
requires a Simulink
Design Verifier™ license. The functionality is available as part of the Variant Manager for Simulink support package.
Comando MATLAB
Hai fatto clic su un collegamento che corrisponde a questo comando MATLAB:
Esegui il comando inserendolo nella finestra di comando MATLAB. I browser web non supportano i comandi MATLAB.
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 MathWorks 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)