Is there any initialization block for parameters and constants in simulink model to be used throughout the model ?

Hi, I know that writting this in matlab script is a way to do it and also creating a variable from simulink is also a way to do it. I think these 2 methods are not neat. I would like to do the opposite have a block to do, initialize all the parameters and constants of the model in simulink. Please let me know what are the ways to do it.

 Accepted Answer

Use a Simulink Data Dictionary (.sldd). Start from here

17 Comments

I am very confused of how to do it. I read the post and also saw video on youtube.
I am using MATLAB 2021b and I am unable to get this step -
  1. In the Simulink Editor, on the Modeling tab, under Design, click Link to Data Dictionary.
Can you please show me where to find it ?
The UI for each version might be different. At the "Design" group, press the "down arrow".
I don't understand the point number 10 either
  1. To open the dictionary, in the Simulink Editor, click the model data badge in the bottom left corner, then click the External Data link. To inspect the contents of the dictionary, in the Model Explorer Model Hierarchy pane, under the External Data node, expand the dictionary node.
I have attached a picture of this
@Fangjun Jiang From my understanding it looks like, I cannot add / create new variables or constants directly in Data Dictionary. Am I correct ?
Yes you can. Open the 'sldemo_fuelsys_dd' demo model. Click the data dictionary icon on the low left corner of the model canvas, and then
@Fangjun Jiang Thanks a lot for the answer. I got it and able to add new variable / data.
I have a question, Is it possible to use this variable or data inside Matlab Function block directly ? without sending as an input port value to the block and directly using it inside the block as it is in the simulink workspace ?
Yes. Inside the MATLAB Function block, add a data, specify it as a "parameter".
@Fangjun Jiang If I add it a parameter inside the Matlab function block, Will it be automatically be present in my data dictionary ? Can I also use it in other places of my simulink model ?
Can you please show a screenshot of it ? I am unable to see that in MATLAB 2021b.
That "parameter" has to come from base workspace, or model worspae, or data dictionary. It can be used anywhere in the model.
@Fangjun Jiang I am unable to find the Ports & Data Manager block to do this change. Can you please show a screenshot of it. I have been trying this for a long time.
I looked at the image in the same function tab and I don't find the Ports & Data tab anywhere. I have attached a screenshot of it. I also read in other questions that it only shows up while we edit and I tried it too, It didn't come up.
No idea. You might have customized toolstrip.
In Simulink, press Ctrl+H to bring up Model Explorer, navigate to the MATLAB Function block on the left. On the right, it is the same UI.
I have not customised anything atleast knowingly. If you know how to bring back the standard toolbar, let me know. I followed the steps through model explorer and it worked. I need to first add it in External data and mention in function block as a parameter and also have it as an argument to the function.
Thanks and it worked :)

Sign in to comment.

More Answers (0)

Products

Release

R2021b

Community Treasure Hunt

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

Start Hunting!