Share a Configuration with Multiple Models - MATLAB & Simulink (original) (raw)

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:

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, typeopenExample('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 .
  4. Select the Configurations node and click the Add Configuration button . The configuration set object appears in theContents 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 modelLinearActuator. 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, typeLinearActuator.
  2. In the Model Explorer, in the Model Hierarchy pane, select the model node.
  3. Select > 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 theLinearActuator model, select the Configurations node. In theContents 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 selectSharedConfig, 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 theLinearActuator model, select the Configurations node. In theContents pane, select the configuration referenceLinActuatorRef.
  2. Right-click the configuration reference LinActuatorRef and select .

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 modelNonLinearActuator.
  3. Name the configuration reference NonLinActuatorRef.
  4. Point the reference to the freestanding configuration setSharedConfig.
  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 > 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, thenOK.
  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 wantLinearActuator 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 > parameter for only the NonLinearActuator model.

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

  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 from the context menu. You can now change the parameter value as you would for any configuration set. For this example, override the parameter > 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 orCancel 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 modelNonLinearActuator 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 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 .
  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 .
  3. Specify the filename for the saved configuration set and select OK. The configuration set object appears in the base workspace.

Configuration Reference Limitations

See Also

Topics