Make parameters available inside Simulink's Matlab functions
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Kushagr Gupta
2017-3-17
编辑:Kushagr Gupta
2017-3-17
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Programmatic Model Editing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!