MATLAB Answers

What is the proper use of programmatic simulink interface : model(t,x,u,flag)? Can I use it to step forward through a simulation while synchronising it with an external matlab script progress.

2 views (last 30 days)
Sanket Diwale
Sanket Diwale on 6 Jul 2015
Answered: Archit Dhanani on 29 Jul 2019
I am trying to run a controller in simulink, which is to be called by an external matlab script interfacing realtime with a physical system at a fixed sampling period. Since changing everything completely to matlab or completely to Simulink will require lots of code to be rewritten, I expected to use the model(t,x,u,'outputs'), model(t,x,u,'update') commands (as described here: to get the output of the controller and the updated state of the controller from simulink, then pass it on the external matlab script. However, the controller states do not get updated (they remain constant at their initial values). The computation is happening only for zero execution time, even though I provide an array of times in the 't' argument. Kindly help me understand how I can do this correctly. Using the 'sim' command doesn't seem like the right way to do this as it would restart the simulation on each call which is more time consuming, we just want to step the simulink controller through a fixed time step on each call, i.e., invoke its solver for a time step and maintain the updated state until the next call.



Community Treasure Hunt

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

Start Hunting!

Translated by