Make parameters available inside Simulink's Matlab functions
2 views (last 30 days)
Show older comments
Hi, I'm working on a Simulink diagram where many blocks are implemented as Matlab function blocks. Most of these blocks have a call like
param = get_param();
inside them, as their calculations depend on a number of parameters. I implemented the parameter function as a function instead of a script to be able to call it from the Matlab function blocks. From what I understand, this way of loading parameters means I create a new copy of the parameter struct for each block that has a call to get_param(), for each timestep. Probably very inefficient.
Ideas for how to do it better? Adding the parameter struct as an input singal to each block is possible, but will clutter my diagram. Using evalin() is also possible, but requires the use of global variables.
0 Comments
Answers (1)
Kushagr Gupta
on 17 Mar 2017
Edited: Kushagr Gupta
on 17 Mar 2017
I would recommend using Data Store Memory Block for the structure parameter and using it as a global variable within the various MATLAB Function blocks.
In order to understand more about it, go through the following link:
A piece of advice, get_param() is an internal MATLAB function too, hence you should try avoiding using the same name, else your implementation will shadow the inbuilt one which could cause issues later on.
0 Comments
See Also
Categories
Find more on Programmatic 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!