Make parameters available inside Simulink's Matlab functions

2 次查看(过去 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.

回答(1 个)

Kushagr Gupta
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.

类别

Help CenterFile Exchange 中查找有关 Programmatic Model Editing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by