Make parameters available inside Simulink's Matlab functions

1 Ansicht (letzte 30 Tage)
Fyhn
Fyhn am 15 Mär. 2017
Bearbeitet: Kushagr Gupta am 17 Mär. 2017
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.

Antworten (1)

Kushagr Gupta
Kushagr Gupta am 17 Mär. 2017
Bearbeitet: Kushagr Gupta am 17 Mär. 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.

Kategorien

Mehr zu Programmatic Model Editing finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by