Simulink.VariantManager.reduceModel
R2026bGenerate 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'.
Examples
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/Bdoc26b_3362262_490040/tp94899556/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/Bdoc26b_3362262_490040/tp94899556/simulink_variants-ex20490563/outdir1/sldemo_variant_subsystems_r.slx'.
Reduce the model by specifying named variant configurations present in the variant configurations object associated with the model.
Simulink.VariantManager.reduceModel('slexVariantReducer',... 'NamedConfigurations',{'config1','config2'});
Successfully created reduced model '/tmp/Bdoc26b_3362262_490040/tp94899556/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/Bdoc26b_3362262_490040/tp94899556/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/Bdoc26b_3362262_490040/tp94899556/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/Bdoc26b_3362262_490040/tp94899556/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/Bdoc26b_3362262_490040/tp94899556/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/Bdoc26b_3362262_490040/tp94899556/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/Bdoc26b_3362262_490040/tp94899556/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/Bdoc26b_3362262_490040/tp94899556/simulink_variants-ex20490563/outdir2/slexVariantReducer_r.slx'.
Input Arguments
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 configurations object (of type Simulink.VariantConfigurations) 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 or struct array. The function automatically determines the data source of each variable.
Note
Specifying both VariableGroups and
NamedConfigurations is not
supported.
Example: 'VariableGroups',
{{'V',1,'W',1},{'V',2,'W',2}}
Specify Variable Names and Values
Specify variant control variable names and values as a cell array.
Simulink.VariantManager.reduceModel('myModel', ... 'VariableGroups', {'V',1,'W',2});
Create Multiple Named Variable Groups
To create multiple named variable groups for a model, 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]}}));
Specify Data Source for Variables
To specify the data source for each variable, use an array of
struct elements with the fields
Name, Value, and
Source. Use this syntax when the same
variable name exists in multiple workspaces and you need to indicate
which workspace contains each variable. If each variable name exists
in only one workspace, the Source field is
optional.
The Source field accepts these
values:
Model name (for example,
'myModel') — Model workspaceBlock path (for example,
'myModel/Variant Subsystem') — Mask workspaceData dictionary filename (for example,
'myDict.sldd') — Data dictionary'base workspace'— Base workspace''or omitted — Automatically determined from the base workspace or data dictionary
For example, to reduce a model where the variable
V exists in both a mask workspace and the base
workspace:
Simulink.VariantManager.reduceModel('myModel', ... 'VariableGroups', ... struct('Name','V', 'Value',1, 'Source','myModel/Variant Subsystem'), ... struct('Name','V', 'Value',2, 'Source',''));
Data Types: cell | struct
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 R2016aStarting in R2026b, Simulink.VariantManager.reduceModel is available in the Simulink
Variant Manager™
product. In releases R2022b through R2026a, the function is available in the Variant Manager for Simulink support package. In earlier releases, the function is available in Simulink.
Simulink.VariantManager.reduceModel supports reducing models that use variant control
variables defined in the mask workspace or model workspace. The function
automatically determines the data source for each variable. You can also reduce
variant parameters (Simulink.VariantVariable objects) defined in the model
workspace.
The VariableGroups name-value argument accepts a
struct array with a Source field to specify the data source for
each variable when the same variable name exists in multiple workspaces.
The Simulink.VariantManager.reduceModel function supports
reducing models that contain Function Element and Function
Element Call blocks.
When you use the Simulink.VariantManager.reduceModel function to
reduce a model that has an associated test harness, the function removes the harness
and its association from the reduced model. Additionally, the function does not
support reducing test harness models.
The ExcludeFiles argument now allows you to exclude
Simulink models (*.slx, *.mdl) outside
the MATLAB root folder during reduction.
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.
The ExcludeFiles argument allows you to exclude Simulink data dictionary files (*.sldd) and MAT-files
(*.mat) outside the MATLAB root folder during reduction.
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.
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.
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- 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)