You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
Is there any initialization block for parameters and constants in simulink model to be used throughout the model ?
4 views (last 30 days)
Show older comments
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
Fangjun Jiang
on 29 Sep 2023
Use a Simulink Data Dictionary (.sldd). Start from here
17 Comments
VIGNESH BALAJI
on 27 Oct 2023
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 -
- In the Simulink Editor, on the Modeling tab, under Design, click Link to Data Dictionary.
Can you please show me where to find it ?
Fangjun Jiang
on 27 Oct 2023
The UI for each version might be different. At the "Design" group, press the "down arrow".
VIGNESH BALAJI
on 27 Oct 2023
I don't understand the point number 10 either
- 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
VIGNESH BALAJI
on 27 Oct 2023
@Fangjun Jiang From my understanding it looks like, I cannot add / create new variables or constants directly in Data Dictionary. Am I correct ?
Fangjun Jiang
on 27 Oct 2023
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
VIGNESH BALAJI
on 27 Oct 2023
@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 ?
Fangjun Jiang
on 27 Oct 2023
Yes. Inside the MATLAB Function block, add a data, specify it as a "parameter".
VIGNESH BALAJI
on 27 Oct 2023
@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 ?
Did you mean the steps followed in this link - Create and Define MATLAB Function Block Variables - MATLAB & Simulink - MathWorks Benelux
Can you please show a screenshot of it ? I am unable to see that in MATLAB 2021b.
Fangjun Jiang
on 27 Oct 2023
For R2021b, see https://www.mathworks.com/help/releases/R2021b/simulink/ug/parameter-arguments-in-matlab-function-block-functions.html
That "parameter" has to come from base workspace, or model worspae, or data dictionary. It can be used anywhere in the model.
VIGNESH BALAJI
on 27 Oct 2023
@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.
Fangjun Jiang
on 28 Oct 2023
Moved: Fangjun Jiang
on 28 Oct 2023
The button on the top left corner, second image, on this link
VIGNESH BALAJI
on 30 Oct 2023
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.
Fangjun Jiang
on 30 Oct 2023
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.
VIGNESH BALAJI
on 30 Oct 2023
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 :)
More Answers (0)
See Also
Categories
Find more on Interactive Model Editing 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!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)