setVariantConfiguration - Set variant configuration for simulation using SimulationInput

  object - MATLAB ([original](https://www.mathworks.com/help/simulink/slref/simulink.simulationinput.setvariantconfiguration.html)) ([raw](?raw))

Main Content

Set variant configuration for simulation using SimulationInput object

Since R2024a

Syntax

Description

[simin](#mw%5Fd2827eb6-dd84-4b60-b785-e96ee369c518) = setVariantConfiguration([simin](#mw%5Fd2827eb6-dd84-4b60-b785-e96ee369c518),[varconfigname](#mw%5Fab1a9a71-cbe3-4d2e-ad24-9047173167e5)) sets the variant configuration varconfigname for the simulation configured using the Simulink.SimulationInput objectsimin.

For models that use variant elements in Simulink®, such as variant blocks and variant parameters, you can create named variant configurations using Variant Manager for Simulink. A variant configuration represents a combination of variant choices across the model hierarchy. Using Variant Manager, you define a variant configuration as a set of variant control variables and their values, which you can use to activate a specific variant path in the hierarchy. Use the setVariantConfiguration method to specify the variant configuration to apply to the model before the simulation runs.

example

Examples

collapse all

This example shows how to programmatically run single or multiple simulations for a variant model by specifying variant configurations as input to the Simulink.SimulationInput object.

Variant elements in Simulink®, including variant blocks and variant parameters, enable you to represent multiple design alternatives within a single model. For such a model, you can create variant configurations to represent combinations of variant choices across the model hierarchy. These configurations comprise a set of variant control variables and their corresponding values, allowing you to activate specific variants within the model hierarchy.

Note: You must install the Variant Manager for Simulink support package using Add-On Explorer to create variant configurations for a model.

Explore Example Model

The slexVariantManagement model has multiple named variant configurations created using Variant Manager. The configurations are stored in a variant configuration data object, vcd, defined in the data dictionary associated with the model.

Open the model:

modelName = "slexVariantManagement"; open_system(modelName);

View the variant configurations in vcd:

vcd = Simulink.VariantManager.getConfigurationData(modelName); cellfun(@(name)(fprintf("%s\n", name)),{vcd.Configurations(:).Name});

LinInterExpNoNoise LinInterExpWithNoise LinInterStd NonLinExterLowFid NonLinExterHighFid SmartAIExterHighFid LinExterHighFid

Run Single Simulation

To simulate the model using a named configuration in vcd, create a Simulink.SimulationInput object, set the VariantConfiguration property in the object to the named configuration, and run the simulation. This variant configuration is temporarily applied to the model, activating only the corresponding variant path in the model hierarchy before simulation.

simInp = Simulink.SimulationInput(modelName); simInp = setVariantConfiguration(simInp,'LinInterExpWithNoise'); simOut = sim(simInp,"ShowProgress","on");

[27-Sep-2024 12:47:27] Running simulations... [27-Sep-2024 12:47:34] Completed 1 of 1 simulation runs

Run Multiple Parallel Simulations

To run multiple simulations using several named configurations present in vcd, create an array of Simulink.SimulationInput objects and set the required configurations. You can use the parsim or batchsim functions to run the simulations in parallel or in batch mode.

simInputs(1:2) = Simulink.SimulationInput(modelName); simInputs = setVariantConfiguration... (simInputs,{'LinInterExpWithNoise','NonLinExterLowFid'}); simOuts = parsim(simInputs,"ShowProgress","on");

[27-Sep-2024 12:47:36] Checking for availability of parallel pool... [27-Sep-2024 12:47:36] Starting Simulink on parallel workers... [27-Sep-2024 12:47:38] Configuring simulation cache folder on parallel workers... [27-Sep-2024 12:47:38] Loading model on parallel workers... [27-Sep-2024 12:47:42] Running simulations... [27-Sep-2024 12:47:50] Completed 1 of 2 simulation runs [27-Sep-2024 12:47:50] Received simulation output (size: 5.29 KB) for run 1 from parallel worker. [27-Sep-2024 12:47:50] Completed 2 of 2 simulation runs [27-Sep-2024 12:47:50] Received simulation output (size: 5.29 KB) for run 2 from parallel worker. [27-Sep-2024 12:47:50] Cleaning up parallel workers...

Input Arguments

collapse all

Simulation specification in which to set the variant configuration name, specified as a Simulink.SimulationInput object or an array of Simulink.SimulationInput objects.

Example: simin = setVariantConfiguration(simin,'NonLinExterLowFid') sets the variant configuration in the simulation configuration stored in theSimulationInput object simin.

Name of variant configuration to apply to the model before simulation runs, specified as a string, a character vector, or a cell array of character vectors.

Example: simin = setVariantConfiguration(simin,'NonLinExterLowFid') sets the variant configuration in the simulation configuration stored in theSimulationInput object simin.

Data Types: char | string

Output Arguments

collapse all

Simulation specification with specified variant configuration name, returned as aSimulink.SimulationInput object or an array of Simulink.SimulationInput objects.

Version History

Introduced in R2024a