# How do I call Matlab code into Simulink for doing a simulation for doing plots?

I have built a simulink model for performing cartesian regulation on a unicycle:

and plot the results with a Matlab code

but, I am not very confident with Simulink and so I don't know how to call these codes into my Simulink model.

There's a Matlab function block. Follow the example and your inputs and outputs will create source/sink connections on the Simulink block to wire in values.

I would only put the controller in there, and don't use the clear all command - if it's not persistent then a variable inside a function ceases to exist between function calls. Every call to the function wipes all the internal variables inside that function.

If you're wanting your data to be plotted at the end then you can use a To Workspace block and send the data out that way and plot from the console or script after the Simulink project finishes.

• Sorry I had to edit my question and delete details, but I was talking to my professor to understand the model he wrote, and he asked me to not share it on internet. I appreciate a lot your help anyway. I tried to keep the essential in order to maintain the sense of the post. Thanks.
– J.D.
Oct 3, 2020 at 8:34
• FYI the edit history is kept and is public on Robotics SE
– 50k4
Oct 4, 2020 at 21:45
• Yes I know, but I cannot delete questions which have been answered. So this is the best I can do I guess. Thanks.
– J.D.
Oct 8, 2020 at 5:30

If you're wanting your data to be plotted at the end then you can use a To Workspace block and send the data out that way and plot from the console or script after the Simulink project finishes