Main Content

Share a Configuration with Multiple Models

To share a configuration set with multiple models, store it as a freestanding configuration set in a Simulink® data dictionary or in the base workspace. By default, a configuration set resides within a single model so that only that model can use it. A freestanding configuration set is a Simulink.ConfigSet object that you store outside of your models so that multiple models can use it.

To use a freestanding configuration set in a model, create a configuration reference in the model that points to the freestanding configuration set. You can then activate the configuration reference in the same way as a standard configuration set. Multiple models can reference the same freestanding configuration set.

Use configuration references when you want to:

  • Use the same configuration parameters in multiple models. When you change parameter values in the freestanding configuration, the changes apply to each model that references the configuration.

    To share a configuration set across a model hierarchy, you can propagate the reference from the top model to its referenced models. For more information, see Share a Configuration Across Referenced Models.

  • Change configuration parameters for any number of models without changing the model files. When you store a configuration set in a Simulink data dictionary, changing parameter values in the configuration changes the data dictionary file. Models that are linked to the data dictionary and reference the configuration set use the new values, but their model files are not changed.

  • Quickly replace the configuration sets of any number of models without changing the model files. When you store a configuration set in a Simulink data dictionary, you can point to that configuration from a reference that is also stored in the data dictionary. Your models can then reference the data dictionary's configuration reference. When you change the data dictionary's reference to point to a different configuration set, the models use the new configuration.

    When a configuration reference references a configuration in the base workspace, it points to a variable that represents the Simulink.ConfigSet object. Assigning a different configuration set to the variable assigns that configuration set to each model that references the variable.

For this example, you store a configuration set in a Simulink data dictionary and reference the configuration set from models that are linked to the data dictionary. To create and link a Simulink data dictionary, see Migrate Models to Use Simulink Data Dictionary. To share a configuration set that is already saved in a model, convert the configuration to a referenced freestanding configuration, as shown in Share a Configuration Across Referenced Models.

Create a Configuration Set in the Data Dictionary

Before you reference a freestanding configuration set from your models, create the configuration in a Simulink data dictionary and link it to your models. For this example, use the Simulink project Airframe. The project contains the Simulink data dictionary system_model and multiple models that are linked to the data dictionary.

  1. Open the project. At the command line, type openExample('simulink/AirframeProjectExample').

  2. In the project folder, in the folder data, double-click the Simulink data dictionary system_model.sldd. The data dictionary opens in the Model Explorer.

  3. In the Model Hierarchy pane, expand the data dictionary node for system_model. Right-click the node and click Show Empty Sections.

  4. Select the Configurations node and click the Add Configuration button . The configuration set object appears in the Contents pane, with the default name, Configuration.

  5. Name the new configuration SharedConfig.

Model Explorer showing the configurations section of the model system_model. The configuration set SharedConfig is shown in the contents pane.

Models that have access to the data dictionary system_model.sldd can reference the new configuration.

Create and Attach a Configuration Reference

To use your freestanding configuration set in a model, attach a configuration reference that points to the configuration set. For this example, use the model LinearActuator. The model is linked to the Simulink data dictionary system_model.sldd, which contains your new configuration SharedConfig.

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

  2. In the Model Explorer, in the Model Hierarchy pane, select the model node.

  3. Select Add > Configuration Reference or click the Add Configuration Reference button .

  4. Under the model node, click Configurations. A new configuration reference named Reference is listed.

  5. Name the configuration reference LinActuatorRef.

Model Explorer showing the configurations section of the model LinearActuator. The configuration reference LinActuatorRef is highlighted in the contents pane.

The new configuration reference is attached to the model, but it does not point to a freestanding configuration yet and it is not active. To complete the setup, resolve and activate the configuration reference.

Resolve a Configuration Reference

An unresolved configuration reference is a configuration reference that is not pointing to a valid configuration set object. When you create a configuration reference by using the preceding steps, the reference is unresolved.

To resolve the configuration reference that you created:

  1. In the Model Hierarchy pane, under the model node for the LinearActuator model, select the Configurations node. In the Contents pane, select the unresolved configuration reference, LinActuatorRef.

    The right pane shows that the configuration reference is unresolved.

    Configuration reference information. The name field shows a warning to specify a configuration name.

  2. Use the Name drop-down menu to select SharedConfig, which you created in the data dictionary.

    Tip

    You can specify the name of a configuration reference instead of a configuration set. However, nesting a configuration reference beyond this depth results in an error.

  3. Click Apply. The warning icon disappears and the reference points to your freestanding configuration set.

If your configuration reference is already resolved, you can follow these steps to change which configuration set it references.

Activate a Configuration Reference

After you create the configuration reference and attach it to the model, activate the reference to use the referenced configuration in the model.

  1. In the Model Hierarchy pane, under the model node for the LinearActuator model, select the Configurations node. In the Contents pane, select the configuration reference LinActuatorRef.

  2. Right-click the configuration reference LinActuatorRef and select Activate.

When the configuration reference is active, the Model Explorer shows the name of the reference with the suffix (Active). The freestanding configuration set now provides the configuration parameters for the model.

Create a Configuration Reference in Another Model

For this example, you will update the configuration set and see how it affects its associated models. Repeat the process above to associate SharedConfig with a second model:

  1. Open the model NonLinearActuator. This model is also linked to the data dictionary that contains the freestanding configuration set.

  2. In Model Explorer, add a configuration reference to the model NonLinearActuator.

  3. Name the configuration reference NonLinActuatorRef.

  4. Point the reference to the freestanding configuration set SharedConfig.

  5. Activate the configuration reference.

Both models now contain a configuration reference that points to the same configuration set object in the Simulink data dictionary.

Change Parameter Values in a Referenced Configuration Set

You can edit a freestanding configuration set by opening it from the Configuration Reference dialog box of a reference that points to the configuration set. Changing the freestanding configuration set affects the configuration references that refer to it, except for parameters that are overridden in those references. To edit the configuration set that you reference from the models:

  1. Open one of the models that references the configuration set. For this example, open the model LinearActuator.

  2. To open the Configuration Reference dialog box, on the Modeling tab, click the Model Settings button . The Configuration Reference dialog box displays a read-only view of the referenced configuration SharedConfig. In the dialog box you can browse, search, and get context-sensitive help for the parameters in the same way you do in the Configuration Parameters dialog box.

  3. At the top of the Configuration Reference dialog box, click the Model Configuration Parameters icon . The Configuration Parameters dialog box opens. You can now change and apply parameter values as you would for any configuration set.

    Note

    Some options in the configuration set cannot be used in a freestanding configuration because they perform actions on one specific model. For example, the Data Import/Export > Connect Inputs button is not supported in freestanding configuration sets because it opens the Root Inport Mapper for the model that uses the configuration.

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

  5. Your applied changes appear in the Configuration Reference dialog box. The models that reference the freestanding configuration SharedConfig use the new solver type.

To programmatically change configuration parameter values in a configuration set stored in a data dictionary, see Manage Configuration Set Stored in Data Dictionary.

Change Parameter Value in a Configuration Reference

You can override individual parameter values for models that reference freestanding configuration sets without changing the freestanding configuration. For an overridden parameter, the reference uses the value you assign locally instead of the value in the referenced configuration set. For example, suppose that LinearActuator and NonLinearActuator are both in the same model hierarchy. You want LinearActuator to be referenced as many times as it needs to be, but want Simulink to return an error if NonLinearActuator is referenced more than one time. In this example, you can override the Model Referencing > Total number of instances allowed per top model parameter for only the NonLinearActuator model.

For this example, override the parameter in the configuration reference for the model NonLinearActuator.

  1. Open the model NonLinearActuator.

  2. To open the Configuration Reference dialog box, on the Modeling tab, click the Model Settings button . The active configuration reference displays a read-only view of the referenced configuration.

  3. Right-click the parameter you want to change and select Override from the context menu. You can now change the parameter value as you would for any configuration set. For this example, override the parameter Model Referencing > Total number of instances allowed per top model and set the value to One.

    In the left pane, each pane displays the number of overridden parameters it contains.

    Configuration reference dialog box referencing the configuration SharedConfig. The parameter Total number of instances allowed per top model is highlighted blue and set to the value One.

  4. Click Apply to keep the changes or Cancel to restore the parameter to the referenced value.

    Changes you make to a parameter value apply only to the configuration reference in which you override and edit the parameter. They do not affect other references to the referenced configuration set. For this example, the model NonLinearActuator allows a top model to reference it once, while the model LinearActuator allows a top model to reference it multiple times.

To restore an overridden parameter to its value from the referenced configuration set, right-click the overridden parameter and select Restore from the context menu. The overridden parameter resets to the value in the referenced configuration and becomes read-only again.

Save a Referenced Configuration Set

If you store your freestanding configuration set in a Simulink data dictionary, you can save changes to the configuration by saving the data dictionary.

If your model references a configuration set that you store in the base workspace, before you exit MATLAB®, you need to save the referenced configuration set to a MAT-file or MATLAB script.

  1. In the Model Explorer, in the Model Hierarchy, select Base Workspace.

  2. In the Contents pane, right-click the name of the referenced configuration set object.

  3. From the context menu, select Export Selected.

  4. Specify the filename for saving the configuration set as either a MAT-file or a MATLAB script.

Tip

When you reopen the model you must load the saved configuration set, otherwise the configuration reference is unresolved. To set up your model to automatically load the configuration set object, see Customize Model Behavior with Callbacks.

Load a Saved Referenced Configuration Set

If your configuration reference uses a configuration set that you exported to a MAT-file or MATLAB script, you need to load the referenced configuration set from the file to the base workspace.

  1. In the Model Explorer, in the Model Hierarchy, right-click Base Workspace.

  2. From the context menu, select Import.

  3. Specify the filename for the saved configuration set and select OK. The configuration set object appears in the base workspace.

Configuration Reference Limitations

  • A configuration reference can point to another configuration reference, but you cannot nest a configuration reference beyond the second reference.

  • If you activate a configuration reference when using a custom target, the ActivateCallback function does not trigger to notify the corresponding freestanding configuration set. Likewise, if a freestanding configuration set switches from one target to another, the ActivateCallback function does not trigger to notify the new target. This behavior occurs even if an active configuration reference points to that target. For more information about ActivateCallback functions, see rtwgensettings Structure (Simulink Coder).

  • Not all parameters in a reference can be overridden, for example, parameters that must be consistent in a model reference hierarchy cannot be overridden.

Related Topics