Main Content

Reduce Models Containing Variant Blocks


You require a Simulink® Design Verifier™ license to reduce your model.

A variant model can contain multiple variable structures and a single fixed structure. The combination of a variable structure and the fixed structure to create a model depends on different combinations of the variant choices that you select. Each combination of the variant choices can be stored as a variant configuration.

Variant models can be reduced to simplified, standalone model depending on the selected variant configurations. Additionally, all related files and variable dependencies are also reduced. These reduced artifacts are packaged into a user-specified output folder.

Consider the model Variant Reducer. The model contains a Variant Source block, a Variant Sink block, and a Variant Subsystem block with these variant choices:

  • Variant Source: V==1 and V==2

  • Variant Sink: W==1, W==2, and W==3

  • Variant Subsystem: V==1 and V==2

Assume that the model has two predefined variant configurations, named config1 (V==1 && W==2) and config2 (V==2 && W==2). These configurations are saved in a variant configuration data object, varConfig.

To reduce the model, perform the following steps:

  1. Right-click the variant badge, and select Open in Variant Manager. The Variant Manager opens displaying the predefined configurations.

  2. Click Reduce model. The Variant Reducer dialog box opens.

  3. In the Reduction mode section, select:

    • Current variant control values : To reduce the model based on its variant control variable values in the global workspace.

    • Specify variant configurations: To reduce the model that is associated with a variant configuration data object and configurations to be retained in the reduced model.


      During reduction, the control variable values from the last selected configuration are stored in the global workspace.

    • Specify variant control values: To reduce the model based on the variant control variable values. You can create multiple variable groups corresponding to different configurations. Click New variable group to set the values for variant control variables. You can either specify a variant control value or select Full-range or Ignored from the drop-down list. Specifying a variant control value as a vector also allows you to reduce a model for all combinations of that variable. For example, if you specify values V = 1 and W = [1,2], then the model is reduced for the configurations {V==1, W==1} and {V==1, W==2}. If you select Full-range as a variant control value, Reference Value column is activated to enter a reference value required for successful model compilation. The model is reduced for all valid values of the specified variant control variable. If you select Ignored as a variant control value, then that variant control variable is not considered while reducing the model.


      To use a full-range variant control variable, Variant activation time in the block parameters dialog of the blocks which uses that Variant control variable must be set to code compile.


    If you invoke variant reduction by specifying variable groups, the reduced model will have the variant configurations corresponding to the variable groups associated with it. This overwrites any existing variant configurations present in the original model.

  4. From Compile mode, select sim to compile the model for simulation or codegen to compile the model in the code generation mode as part of reducing the model. If the model contains variant blocks with the Variant control mode parameter set to sim codegen switching, you can select 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.

  5. Select Preserve signal attributes to preserve the compiled signal attributes between the original and reduced model. When this option is selected, the Variant Reducer tries to preserve the compiled signal attributes between the original and reduced models by adding signal specification blocks at appropriate block ports in the reduced model. Compiled signal attributes include signal data types, signal dimensions, compiled sample times, and so on.

  6. Select Generate detailed summary to generate the Variant Reducer summary in the output folder. The Variant Reducer summary contains summary of Variant Reducer Options, Original and Reduced Model Differences, Dependent Artifacts, Callbacks and Warnings. For more information, see Generate Variant Reducer Summary.


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

  7. Specify a value as the suffix in the Model suffix field. The model suffix value is appended to the reduced models, data dictionaries, and the related artifacts. By default, _r is the suffix.

  8. Specify the output folder to store the reduced model.


    Selecting the Open reduced model check box changes the current working folder to the output folder.

  9. Click Reduce. The reduced model for the required configurations are now created. If the model contains resolved library links or referenced models, the corresponding parent is reduced for the specified configuration and is referenced in the model. The reduced model, reduced referenced model, and the reduced library get their names from the corresponding model, referenced model, or the library with _r (Model suffix) appended to it.

Consider a Variant model that contains a Simulink Function block with Variant condition on the Simulink Function block as V==1 || V==2 || V==3 || V==4. If the model is reduced for any or a combination of the available Variant conditions, the Simulink Function block in the reduced model is unconditional. For example, if the model is reduced for Variant condition, V=1, V=2, and V=3, the Simulink Function block in the reduced model is unconditional. Whereas, if the model is reduced for Variant condition, V=1, V=2, and V=5, the Simulink Function block in the reduced model remains conditional with V==1 || V==2 as the Variant condition.

Reduce Model Programmatically

To reduce a model programmatically, use the syntax:


For example,

  • To reduce the model based on its variant control variable values in the global workspace.

  • To reduce the model based on its variant control variable values in the global workspace to a specified folder.

    Simulink.VariantManager.reduceModel('sldemo_variant_subsystems', 'OutputFolder', 'outdir')
  • To reduce the model that is associated with a variant configuration data object and configurations to be retained in the reduced model.

    Simulink.VariantManager.reduceModel('sldemo_variant_subsystems','NamedConfigurations', {'LinInterStd','NonLinExterHighFid'})
  • To reduce the model by specifying configurations in the form of a structure of variant control variables.

    Simulink.VariantManager.reduceModel('iv_model', 'VariableConfigurations', {'V',1,'W',[1 2]})

    Here, two configurations are specified corresponding to {V=1, W=1} and {V=1, W=2}, respectively.

  • To reduce the model by specifying variant control values where 'w' is a full-range variant control value.


    Here, four configurations are computed corresponding to {V==1, W==1}, {V==1, W==2}, {V==1, W==3} and {V==1, W==0} respectively.

For more information on reducing model programmatically, see reduceModel.

Generate Variant Reducer Summary

Variant Reducer provides an option to generate a detailed report of the reduction process as an HTML file. The report is saved in the output folder where reduced artifacts are saved.


A Simulink Report Generator™ license is required to generate a Variant Reducer summary.

The Variant Reducer summary can be used to:

  • Verify the input and output options used for reduction, for example, the input variant configuration and the output folder location.

  • Analyze the differences between the original model and the reduced model, for example:

    • Blocks that have been inserted, deleted, or modified.

    • Masks that have been modified.

    • Dependent data files or Simulink cache files that have been modified.

  • Identify any warnings.

  • Identify if the model is reduced for the code generation branch.

  • Identify components that were not reduced and determine the manual updates that may be required, for example, callback code and Stateflow® variant transitions.

  • Navigate the interactive views of the original and reduced models.

To generate the report from the Variant Reducer dialog box, select the Generate detailed summary check box during reduction. To generate the report while reducing the model programmatically, set the 'GenerateSummary' name-value argument to true. For example, this command generates the summary and saves it to the path L:\Models\variantReducerRpt.

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

variant reducer summary

Considerations and Limitations

  • Reduction of models that contain the Variant Connector block is not supported.

  • Reduction of models that contain variant blocks with the Variant activation time parameter set to startup is not supported.

  • The output folder to store the reduced model must not be under matlabroot.

  • If the output folder contains the variant_reducer.log file from the previous model reduction, the reducer overwrites all the files available in that output for any subsequent reduction.

  • Additional blocks are added automatically to the reduced model to ensure consistent simulation semantics. Additional blocks can include Signal Specification blocks for consistent signal attributes (data type, dimensions, complexity) or the Ground and the Terminator blocks for unconnected signals.

  • During model reduction, commented blocks present on the active path are retained while the commented blocks present on an inactive path are deleted.

  • Signal attributes (data type, complexity, dimensions) coming from the inactive elements in Stateflow charts may not be retained in the reduced model.

Model Components That Are Not Reduced

These model components are not reduced automatically and may require manual intervention. To identify such artifacts, generate the Variant Reducer summary by selecting the Generate detailed summary check box in the Variant Reducer dialog box during model reduction.

  • Callback code:

    • Callbacks such as InitFcn, PreLoad, PostLoad, mask initialization code, and mask parameter callback code must be modified manually.

    • Callback code in the inactive variant components are removed. This can cause unexpected behavior in the reduced model.

  • During model reduction, elements in the Stateflow canvas, including variant transitions are not modified.

  • If a model has dependencies on files that are located under matlabroot (Simulink libraries, .m files, .mat files, or .sldd files), they are not modified or copied to the output folder during model reduction.

  • Variant parameter objects (instance of the Simulink.VariantVariable class) are not reduced.

Related Examples

More About