Systematically pause Simulink model and continue from Matlab command line

68 次查看(过去 30 天)
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.

采纳的回答

Kaustubha Govind
Kaustubha Govind 2013-7-2
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 个评论
Kaustubha Govind
Kaustubha Govind 2013-7-3
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 2013-7-3
After looking through this example in more detail, I think this was the best option. Thanks!

请先登录,再进行评论。

更多回答(3 个)

Guru
Guru 2013-7-3
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 2013-7-2
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 个评论
Thomas Marullo
Thomas Marullo 2013-7-3
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 2020-3-11
编辑:Daniel Rutherford 2020-3-11
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.

请先登录,再进行评论。


Thomas Marullo
Thomas Marullo 2013-7-3
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.

类别

Help CenterFile Exchange 中查找有关 Event Functions 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by