How to pass a data dictionary parameters as an argument in a model reference?

Hello!
I have a model with four instances of a model reference, each instance store its parameters in a data dictionary.
I want to pass different values to those parameters in each instance, but I cannot set those parameters as an arguments.
How is it possible to set a data dictionary parameters as an argument?

Answers (1)

I don't think there is a direct way to do this currently in R2020a. I suggest you try a workaround.
Specify an argument, which is the name of the data dictionary file, for the model reference. In the PreLoadFcn callback of the model, load the specified data dictionary.

4 Comments

Thank you for your answer!
I tried your suggestion, but I think I didn't fully understood it.
Can you please attach a small demo project? or, to explain the first sentence of the workaround?
In the model itself, create a variable called DataDictFileName in its model workspace. In the PostLoadFcn (probably better than PreLoadFcn) callback, read the value of DataDictFileName and use data dictionary API to load the data dictionary.
When the model is referenced, specify DataDictFileName as an augument and provide different data dictionary file name.
Hi Fangjun Jiang, I tried your suggestion but without any luck.
I get an error that is caused by: Unrecognized function or variable 'DataDictFileName'.
And there is another error: Invalid setting in 'RefLevel/Model' for parameter 'DataDictFileName'.
The variables in model workspace can be referenced by name directly in the Simulink model. To access it through script in MATLAB, you need to use API.
In the PostLoadFcn call back, do this
hws = get_param(bdroot, 'modelworkspace')
hws.getVariable('DataDictFileName')

Sign in to comment.

Categories

Find more on Manage Design Data in Help Center and File Exchange

Products

Release

R2020a

Asked:

on 11 Mar 2021

Commented:

on 16 Mar 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!