The ability to pause execution of a MATLAB file without pausing an external Simulink simulation is not available in MATLAB.
To work around this issue, you can use either the KEYBOARD function or MATLAB timer objects.
Inserting the KEYBOARD command stops execution of the file and gives control to the keyboard, allowing the user to determine manually when to continue execution. This requires manual user input.
You can automate the required functionality using MATLAB timer functions. The WAIT function in MATLAB pauses execution of a MATLAB file while allowing a Simulink simulation to continue. Here is an example of how this could be done:
for j = 1:50
T = timer('TimerFcn',@init_sim);
start(T)
end
function init_sim(obj,event)
set_param(gcs,'SimulationMode','external')
set_param(gcs,'SimulationCommand','connect')
set_param(gcs,'SimulationCommand','start')
wait(obj)
end
In this example, you must stop the timer object using one of the "StopFcn" callback functions in the model. To do this, use the following command:
evalin('caller', 'stop(obj)')
Best Answer