MATLAB: How to invoke the Simulink debugger from within a MATLAB script and issue subsequent debugger commands in Simulink 7.5 (R2010a)

debuggersimsetsimulinksldebug

I want to start the Simulink debugger from within a MATLAB script, and issue debugger commands subsequently. However, I see that once I invoke the SLDEBUG command within my script, control transfers to the debugger prompt, and I am unable to issue debugger commands from within the script.

Best Answer

You can use either of the following two approaches to call SLDEBUG on a model from within a script, and subsequently execute debugger commands.
Approach 1: Create a cell array of commands that you want to execute in debug mode, and then call the SIM command with the cell array as an argument.
cmds = {'slist','step top','step top','stop'};
sim('vdp','debug',cmds);
Approach 2: Create a SIMSET, a cell array consisting debugger commands, and then pass the SIMSET as an argument to the SIM command.
cmds = {'slist','step top','step top','stop'};
opts = simset('debug',cmds);
sim('vdp',[],opts);
Note, however, that the SIMSET feature may be deprecated in a future release of MATLAB.