Main Content

Manage Configuration Sets for a Model

A model configuration set is a named collection of values for the parameters of a model.

You can associate multiple sets of parameter values with your model. The configuration sets associated with a model can specify different values for any or all configuration parameters. The model uses the parameter values of the active configuration. You can quickly change the active configuration to any of the configuration sets that are attached to the model.

Use multiple configuration sets in a model when you want to:

  • Compare the difference in model execution after changing the values of several parameters.

  • Use different configurations for your model when you use the model in different contexts.

For this example, you set up the model sldemo_fuelsys_dd to have two configuration sets that specify different solvers. You then copy one of the configurations to the model vdp and compare it with the default configuration set of vdp.

Create a Configuration Set in a Model

The model sldemo_fuelsys_dd contains one configuration set, which uses a variable-step solver. Add another configuration to use a fixed-step solver.

  1. Open the model. At the command line, type sldemo_fuelsys_dd.

  2. Open the Model Explorer. On the Modeling tab, click Design > Model Explorer.

  3. In the Model Hierarchy pane, expand the model node and select the model name sldemo_fuelsys_dd.

  4. You can create a new configuration set in any of these ways:

    • From the Add menu, select Configuration.

    • On the toolbar, click the Add Configuration button .

    • Select the Configurations node below the model node. In the Contents pane, right-click an existing configuration set and copy and paste the configuration set.

  5. Select the Configurations node below the model node. The new configuration set, Configuration1, appears in the Contents pane. The default configuration, Configuration, is still the active configuration for the model.

  6. On the Contents pane, double-click the name Configuration1 and rename the configuration to FixedStepConfig. You specify the fixed-step solver in the following section.

  7. Rename the configuration Configuration to VariableStepConfig.

Change Configuration Parameter Values in a Configuration Set

To change the parameter values of a configuration set, open the Configuration Parameters dialog box for that configuration. You can open and change any configuration set, whether or not it is active.

For this example, change the configuration FixedStepConfig to specify a fixed-step solver instead of the default variable-step solver.

  1. Open the Model Explorer.

  2. Expand the model node and select the Configurations node below it.

  3. In the Contents pane, right-click the configuration set FixedStepConfig and click Open.

    The configuration set opens in the Configuration Parameters dialog box.

    Note

    Every configuration set has its own Configuration Parameters dialog box. As you change the state of a configuration set, the title bar of the dialog box changes to reflect the state.

  4. On the Solver pane, set the Type parameter to Fixed-step. Click OK.

The model now contains two configurations, VariableStepConfig and FixedStepConfig, which use different solver types. You can compare how the solver settings affect simulation by changing the active configuration and simulating the model.

Activate a Configuration Set

Only one configuration set associated with a model is active at any given time. The active set determines the current values of the model parameters. You can change parameter values in the active or inactive set at any time (except when executing the model). In this way, you can quickly reconfigure a model for different purposes, such as testing and production.

To activate the fixed-step configuration that you created in the previous section:

  1. Open the Model Explorer.

  2. Expand the model node and select the Configurations node below it.

  3. In the Contents pane, right-click the configuration set FixedStepConfig and click Activate.

    The active configuration displays (Active) to the right of the configuration name.

Copy, Delete, and Move a Configuration Set

You can use the Model Explorer Edit or context menus to delete, copy, and move configuration sets among models displayed in the Model Hierarchy pane.

For this example, copy your configuration FixedStepConfig to the model vdp.

  1. Open the model vdp and open the Model Explorer.

  2. In the Model Hierarchy pane, expand the node of the model sldemo_fuelsys_dd and select the Configurations node below it.

  3. In the Contents pane, right-click FixedStepConfig and click Copy in the context menu.

  4. In the Model Hierarchy pane, right-click the model node vdp and click Paste.

  5. Activate the configuration FixedStepConfig for the model vdp.

To copy the configuration set using drag-and-drop, hold down the right mouse button and drag the configuration set to the Configurations node of the model in which you want to create the copy.

To move a configuration set from one model to another using drag-and-drop, hold the left mouse button down and drag the configuration set to the Configurations node of the destination model.

Note

You cannot move or delete an active configuration set from a model.

Save a Configuration Set

When you store a configuration set in a model, the configuration set is saved when you save the model. Alternatively, you can store the configuration set outside of the model as a freestanding configuration set to share the configuration with other models. You can save the configuration set in a Simulink® data dictionary, or export the configuration set to a MAT-file or to a script. If you store a freestanding configuration set in the base workspace, to save it, you must export it to a MAT-file or script.

Simulink Data Dictionary

To save your configuration set outside of the model, store the configuration in a Simulink data dictionary. You can share and archive the configuration by using the data dictionary. To use the configuration in a model, use a configuration reference. For more information, see Share a Configuration with Multiple Models.

Exported File

You can also save the settings of a configuration set as a Simulink.ConfigSet object in a MAT-file or as a MATLAB® function or script. Export the configuration set to a MATLAB function or script when you want to compare the settings in different configuration sets. However, when you want to preserve a freestanding configuration set, exporting the configuration to a file is not recommended because you must manually load the configuration set when you want to use it. Save the configuration set in a Simulink data dictionary instead.

For this example, use the Model Explorer to save the configuration set FixedStepConfig, which you copied to the model vdp.

  1. Open the Model Explorer.

  2. In the Model Hierarchy pane, expand the model node vdp and select the Configurations node below it.

  3. In the Contents pane, right-click the configuration FixedStepConfig and select Export.

  4. In the Export Configuration to File dialog box, specify the name of the file and the file type. For this example, save the configuration as FixedStepConfig.m.

    If you specify a .m extension, the file contains a MATLAB function that creates a configuration set object. If you specify a .mat extension, the file contains a configuration set object.

    Note

    • Do not specify the name of the file to be the same as a model name. If the file and model have the same name, the software cannot determine which file contains the configuration set object when loading the file.

    • To use the configuration set in a later release, specify a .mat extension. If you specify a .m extension, in rare cases, parameter values might change due to changing dependencies.

  5. Click Save. The Simulink software saves the configuration set.

Load a Saved Configuration Set

To load the configuration set that you saved from the model vdp:

  1. Open the model vdp.

  2. Open the Model Explorer.

  3. In the Model Hierarchy pane, right-click the model and select Configuration > Import.

  4. In the Import Configuration From File dialog box, select the M file that contains the function to create the configuration set object, or the MAT-file that contains the configuration set object. For this example, select FixedStepConfig.m.

  5. Click Open. The Simulink software loads the configuration set.

    Note

    • If you load a configuration set object that contains an invalid custom target, the software sets the System target file (Simulink Coder) parameter to ert.tlc.

    • If you load a configuration set that contains a component that is not available on your system, the parameters in the missing component are reset to their default values.

Compare Configuration Sets

When you save two configuration sets as M files or as MAT-files, you can visually compare them by using the visdiff function. This function opens the Comparison Tool and presents the differences between the two files. For more information about the Comparison Tool, see Compare Simulink Models.

For this example, compare the default configuration Configuration to the configuration FixedStepConfig, which you copied to the model vdp.

  1. Save the configuration FixedStepConfig to the file FixedStepConfig.m, as shown in Save a Configuration Set.

  2. Save the second configuration, Configuration, to the file DefaultConfig.m by following the same procedure.

  3. Compare the files.

    visdiff('FixedStepConfig.m','DefaultConfig.m');

Related Topics