필터 지우기
필터 지우기

Systematically pause Simulink model and continue from Matlab command line

조회 수: 67 (최근 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