# 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.

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.