How to pass a data dictionary parameters as an argument in a model reference?
Show older comments
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)
Fangjun Jiang
on 11 Mar 2021
0 votes
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
Jonathan Helderen
on 14 Mar 2021
Fangjun Jiang
on 14 Mar 2021
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.
Jonathan Helderen
on 15 Mar 2021
Fangjun Jiang
on 16 Mar 2021
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')
Categories
Find more on Manage Design Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!