could the data dictionary be used as kind of struct like variables in workspace ?

I just want to use the parameters in data dictionary in the form of struct such as
I tried many methods without success. is there any method to realize this as one with workspace like Param.k1?

10 Comments

You can use structs in data dictionaries. It's probably easiest to define the struct in the base workspace and then copy paste it to the DD.
Thank you for the comment.
Actually I had tried this without success before.
Were you able to make it work now? If not, try creating the struct object in the base workspace and within the model explorer copy and paste it into your data dictionary. Alternatively, you can try to add a normal MATLAB variable into your data dictionary and enter "struct" for its value? What version are you using?
it didn't work.(exactly both create variables in workspace and copy to dd)
I tried both on 2017B and 2022A.
This should work in older releases - I have created a small example in R2020a
Can you share the version of 2017b or 2018a? Please.
Right now the 2020 is not available.
You should be able to open the model with your R2022a version? Or do you only have 17b/18b available?
Hi @ED,
After storing the struct in the dictionary have you tried linking the dictionary to the model. If not please follow the below steps to link the dictionary to the Simulink model (Also make sure you have saved the changes in the dictionary):
  • Open the Simulink model.
  • Open "Modelling Tab".
  • From the drop down in "Design" section select "link to data dictionary" option and link the required data dictionary file where the struct is stored.
  • Run the model after entering the required parameters.
Hi Adarsh and Daniel:
Both the dd can be used with struct, but when it comes to code generation, the variables are replaced by values other than tunable variables.
So does any method that struct in data dictionary be used in model and are embodied in the code generated?

Sign in to comment.

Answers (1)

Hi @ED,
I understand that you are trying to use a struct to store the parameters in a Simulink data dictionary and utilizing it for “Code generation” for the Simulink model.
Firstly, link the dictionary to the model using the following steps:
  • Open the Simulink model.
  • Open "Modelling Tab".
  • From the drop down in "Design" section select "link to data dictionary" option and link the required data dictionary file where the struct is stored.
  • Run the model after entering the required parameters.
Now, In the Embedded coder, click on “Generate Code” button. Once the code is generated check if the parameters are “inlined” or in “tunable” state. If the parameters are “inlined” then it is due the optimizations enabled while code generation.
You can resolve this by following the below steps:
  1. Open “Model Settings” in the “Modeling” tab.
  2. Goto “Code Generation” section and click on “Optimization” under it.
  3. Change the “Default parameter behavior” option from “Inlined” to “Tunable” and run the code generation once again to use the “struct” instead of “values”.
Hope this helps!

Categories

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

Asked:

ED
on 28 Mar 2025

Answered:

on 2 May 2025

Community Treasure Hunt

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

Start Hunting!