MATLAB: Is it possible to convert a Simulink Model into a Matlab function

functionsmatlab functionsimulink

Hi everybody!
I am new to Matlab and Simulink and I wonder if it is possible to convert a Simulink Model into a Matlab function to be invoked in a .m script.
For example, my Simulink Model has got two imputs, A and B, and a output, U. Is it possible to generate the function
'myModel'
and then to use it, writing
U = myModel(A, B);
in my script?
Thank you very much!

Best Answer

You can run your simulink model from any script by the command sim, for inputs and outputs, your simulink model can communicate with data from workspace (To workspace block), or from file (from file block) and export the result to workspace (To workspace block) or to a file (To file block).