Systematically pause Simulink model and continue from Matlab command line

18 visualizaciones (últimos 30 días)
Is it possible to have Matlab start a Simulink model (fixed step, discrete) and after each sample step, the model pauses, allows Matlab to do some data handling from the model, then waits for Matlab to tell the model to resume the next sample step? I have a very specific application that requires some functions in Matlab but I want to use Simulink to handle most of the heavy lifting.

Respuesta aceptada

Kaustubha Govind
Kaustubha Govind el 2 de Jul. de 2013
What kind of data handling would you like to do in MATLAB? You might want to look at Access Block Data During Simulation, which lets you work your MATLAB code into the simulation process instead of artificially pausing/continuing.
  3 comentarios
Kaustubha Govind
Kaustubha Govind el 3 de Jul. de 2013
Thomas: The interface in the link I posted doesn't provide arbitrary access, but is indeed step-by-step - if you read the documentation, you will see that the mechanism involves attaching a PostOutputs callback to a specific block, so your function is called at every step that the block produces new outputs. It doesn't matter how long your code takes to execute - Simulink should wait until it's done.
Thomas Marullo
Thomas Marullo el 3 de Jul. de 2013
After looking through this example in more detail, I think this was the best option. Thanks!

Iniciar sesión para comentar.

Más respuestas (3)

Guru
Guru el 3 de Jul. de 2013
Honestly, this is easier to do if you use MATLAB blocks within your Simulink to validate the results that you are looking for. However you can either use the Simulink Debugger commands from MATLAB to step through each individual block output based on sorted order, or you use:
set_param('model_name','SimulationCommand','pause') set_param('model_name','SimulationCommand','start') set_param('model_name','SimulationCommand','stop')
which are the command line functions that are equivalent to clicking the pause, play, stop buttons respectively.

Guy Rouleau
Guy Rouleau el 2 de Jul. de 2013
In most cases where I have seen users asking to control the execution of a model from MATLAB code, the most appropriate solution was to include the MATLAB code inside the simulation and let simulink control the execution.
Whatever data you wan to extract from the model at every step should be available on a signal line. So you it should be possible to feed it to a block that you can code with MATLAB code (MATLAB Function block, MATLAB s-function, interpreted MATLAB Function block, etc.) The block will do your processing and it will be available as a signal to other blocks for the next step.
  4 comentarios
Thomas Marullo
Thomas Marullo el 3 de Jul. de 2013
The problem with using MATLAB inside of Simulink is that the code is not conducive to Simulink sampling. I am running a script, interpreting the results visually then deciding to continue or not. Simulink needs to wait for me to respond.
Daniel Rutherford
Daniel Rutherford el 11 de Mzo. de 2020
Editada: Daniel Rutherford el 11 de Mzo. de 2020
So, if I have a legacy matlab simulation (lets say a seeker), and Bubba wants me to use state dynamics from a 3-DOF Simulink Simulation to provide kinematic information periodically for each seeker update dwell, I should trash my legacy, 2000 hour test matlab simulation, and throw it into the disfunctionality of simulink? I'd rather rewrite the 3DOF in a matlab script.
There needs to be a better effort by matlab to integrate simulink results into a matlab script.
Preferably, I'd like to use a simulink model like I use the call to an ode function.

Iniciar sesión para comentar.


Thomas Marullo
Thomas Marullo el 3 de Jul. de 2013
Thanks for all your help. The method I used is by having a model run continuously and having triggered subsystems. Matlab command line triggers the system by using set_param to toggle a variable and then read back the data.

Categorías

Más información sobre Simulink Functions en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by