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.ConfigSetobject. 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.
Open the project. At the command line, type
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.
In the Model Hierarchy pane, expand the data dictionary node for
system_model. Right-click the node and click Show Empty Sections.
Select the Configurations node and click the Add Configuration button . The configuration set object appears in the Contents pane, with the default name,
Name the new configuration
Models that have access to the data dictionary
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
Open the model. At the command line, type
In the Model Explorer, in the Model Hierarchy pane, select the model node.
Select Add > Configuration Reference or click the Add Configuration Reference button .
Under the model node, click Configurations. A new configuration reference named
Name the configuration reference
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:
In the Model Hierarchy pane, under the model node for the
LinearActuatormodel, select the Configurations node. In the Contents pane, select the unresolved configuration reference,
The right pane shows that the configuration reference is unresolved.
Use the Name drop-down menu to select
SharedConfig, which you created in the data dictionary.
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.
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.
In the Model Hierarchy pane, under the model node for the
LinearActuatormodel, select the Configurations node. In the Contents pane, select the configuration reference
Right-click the configuration reference
LinActuatorRefand 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
with a second model:
Open the model
NonLinearActuator. This model is also linked to the data dictionary that contains the freestanding configuration set.
In Model Explorer, add a configuration reference to the model
Name the configuration reference
Point the reference to the freestanding configuration set
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:
Open one of the models that references the configuration set. For this example, open the model
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.
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.
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.
On the Solver pane, set the Type parameter to
Fixed-step. Click Apply, then OK.
Your applied changes appear in the Configuration Reference dialog box. The models that reference the freestanding configuration
SharedConfiguse the new solver type.
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
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
For this example, override the parameter in the configuration reference for the model
Open the model
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.
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
In the left pane, each pane displays the number of overridden parameters it contains.
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
NonLinearActuatorallows a top model to reference it once, while the model
LinearActuatorallows 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.
In the Model Explorer, in the Model Hierarchy, select Base Workspace.
In the Contents pane, right-click the name of the referenced configuration set object.
From the context menu, select Export Selected.
Specify the filename for saving the configuration set as either a MAT-file or a MATLAB script.
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.
In the Model Explorer, in the Model Hierarchy, right-click Base Workspace.
From the context menu, select Import.
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
ActivateCallbackfunction does not trigger to notify the corresponding freestanding configuration set. Likewise, if a freestanding configuration set switches from one target to another, the
ActivateCallbackfunction 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
ActivateCallbackfunctions, 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.