MATLAB: Can I run a script in the InitFcn model callback

callbackinitfcnscriptsimulink

I have a model that uses several variables external to the model. For the moment, I copy-paste the definition of all the variables in the InitFcn callback of the Simulink model, although it would be ideal to have these variables in a script, and call the script in the InitFcn callback. Is this possible to implement?

Best Answer

Yes, the text area of the InitFcn callback works like a MATLAB Command Window, so you can simply call a script with its name in the InitFcn callback, and define all the simulation variables in the script.