Initialize variables and parameters for Matlab Function Block - Simulink

16 views (last 30 days)
Hello,
I'm using a Matlab Function Block in my Simulink model. This function needs many parameters to be run, as well as an initialization of the variables. Moreover, the block is in a feedback loop, so to be efficient I want all these parameters previously defined at the begining of the simulation. I simply tried to compute them and to put them in the workspace with Matlab but it doesn't work (while it works for other Simulink blocks like Gain, why ?).
So I've tried to use callback function. According to my problem and to what I've read, I used Initfcn but it doesn't work. I've tried Model callback, Block callback (so in the Matlab function block), and even tried other callback functions such as LoadFcn, OpenFcn, PreLoadFcn, etc. but nothing works. Each time, I have the message "Undefined function or variable" for all the variables in my Matlab function when I run the simulation.
I've also read some stuff about Data Store Memory but I don't think it is the good solution for my problem, as there are many parameters to define (about 40) and I don't want them to be the input of my Matlab function block (expect if it is doable with only one "big input" which brings togather all my parameters ?). Same thing for the "Add Parameter Arguments" method, which I think doesn't correspond to what I need, as it involves supplementary arguments in the Matlab function.
Thank you in advance for your help !

Answers (0)

Community Treasure Hunt

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

Start Hunting!