Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

m-file waiting for simulink simulation

728 views
Skip to first unread message

Hugo Mendonça

unread,
Apr 28, 2013, 5:57:09 AM4/28/13
to
Hi, everyone!

In a m-file I execute a routine that calls a simulink simulation. No problem so far. However, my routine continues after the simulink simulation with data from it.

The point is: how to make the m-file running wait for the simulink simulation finishing?

Thanks.

Hugo Mendonça

unread,
Apr 28, 2013, 6:47:09 AM4/28/13
to
"Hugo Mendonça" <aga...@hotmail.com> wrote in message <klirpl$nni$1...@newscl01ah.mathworks.com>...
I've found this solution in http://www.mathworks.es/support/solutions/en/data/1-1MQV53/?product=WT&solution=1-1MQV53 .

for j = 1:50
T = timer('TimerFcn',@init_sim); %initialize timer object
start(T) %start timer object running
end

function init_sim(obj,event) %timer object callback function
set_param(gcs,'SimulationMode','external') %simulate Simulink model
set_param(gcs,'SimulationCommand','connect')
set_param(gcs,'SimulationCommand','start')
wait(obj) %wait for timer object to stop running (occurs when simulation is finished)
end

Bur I really couldn't understand it.

Phil Goddard

unread,
Apr 28, 2013, 6:38:09 PM4/28/13
to
MATLAB's "sim" function, i.e. the usual way to call a Simulink model from MATLAB, is blocking, i.e. it waits until the model finishes executing before the next line of code gets exectuted.

Although I note that you seem to be be using external mode, and I'm not sure of sim's behaviour in that case.

Phil.

Hugo Mendonça

unread,
Apr 29, 2013, 10:38:09 AM4/29/13
to
"Phil Goddard" <ph...@goddardconsulting.ca> wrote in message <klk8ch$fud$1...@newscl01ah.mathworks.com>...
> MATLAB's "sim" function, i.e. the usual way to call a Simulink model from MATLAB, is blocking, i.e. it waits until the model finishes executing before the next line of code gets exectuted.
>
> Although I note that you seem to be be using external mode, and I'm not sure of sim's behaviour in that case.
>
> Phil.

Phil,

This is what I really needed! Thank you very much!

To start the simulink I was using:
set_param('model','SimulationCommand','Start')

So, it runs the simulink and at the same time runs the code.

I have changed for your suggestion and, now, the code waits for the simulink simulation.

Once again, thank you!

Hugo
0 new messages