Guy on Simulink

Simulink & Model-Based Design

Referencing Configuration Sets for Model Reference

A few weeks ago I described the possibility of storing more multiple configuration sets in a single model.

Today we will do the opposite: Sharing one configuration set among multiple models.

Reference Configuration Set

By default, in Simulink, the configuration of a model is stored in the model file itself.

However when you have a hierarchy of referenced models, those models must have similar configuration sets. Instead of having each model storing its own configuration, it is possible to have all models refer to a single configuration set.

To begin, setup the configuration you want in one model and convert it to a configuration reference:

Converting to reference configuration

A dialog will allow you to specify the name of the configuration set and give you the possibility to save it to a MAT-file or a MATLAB script.

Specifying the name and file of the configuration set

Note that if you do not save the configuration set at this time, it is always possible to save it later using Simulink.BlockDiagram.saveActiveConfigSet

Once the configuration object is in the base workspace, you can configure all your child models to refer to it:

Update: This can be done by right-clicking on the top model configuration reference and selecting Propagate to Referenced Models

Multiple model referencing the same configuration

That way if the configuration needs to change, you will need to make the change in only one place.

Creating Variants of a common configuration set

In a hierarchy of referenced models, it is common to want all the child models to have almost the same configuration, except a few parameters. For example, in the following model I want the three child models to have all the same configuration, except I want child3.slx to execute at a different sample time.

Multiple model referencing similar configuration

To make that happen, I stored a configuration named myConfig in a MATLAB script configFile.m. In an initialization script that I execute before running my model (for example the model PreLoadFcn callback), I copy this configuration set and modify the parameter I need.

Creating a configuration set based on an existing configuration set

That way, I can configure child3.slx to refer to myConfigTS2. If, in the future, I need to change a parameter in all the child models, I only need to do it once in configFile.m. When my initialization script will create myConfigTS2, it will automatically inherit this change.

Now it's your turn

Do you take advantage of configuration reference? Let us know by leaving a comment here

|
  • print

Comments

To leave a comment, please click here to sign in to your MathWorks Account or create a new one.