Main Content


Start simulation debugging session for Simulink model



    sldebug(mdl) starts a programmatic simulation debugging session for the model specified by mdl. The simulation starts and pauses just before the initialization phase.

    When you start a programmatic simulation debugging session, the MATLAB® command prompt becomes the sldebug command prompt. Instead of >>, you see (sldebug @0): >>. To control the debugging session, enter commands in the MATLAB Command Window, at the sldebug command prompt, using the Simulink® debugging programmatic interface.

    During a programmatic simulation debugging session, you can use the debugging functions to:

    • Set model, signal, and block breakpoints

    • Run the simulation one block method at a time

    • Run the simulation one time step at a time

    • Continue the simulation to the next breakpoint

    • Examine simulation data

    To end a programmatic simulation debugging session, use the stop function.


    collapse all

    Start and then stop a simulation debugging session for the model vdp.

    Open the model vdp.


    Use the sldebug function to start the simulation debugging session for the model.

    [TM = 0                      ] simulate(vdp)

    The MATLAB command prompt changes from >> to (sldebug @0): >> to indicate that a debug simulation is in progress and that the Simulink debugging programmatic interface is available.

    Use the step command to step the simulation to the start of the next major time step.

    step top
    [TM = 0                      ] vdp.Outputs.Major

    You can continue using the step command to progress the simulation and observe the results in the Scope block.

    Use the stop function to stop the debug simulation.

    % Simulation stopped

    Input Arguments

    collapse all

    Name of model to debug, specified as a string or a character vector.

    Example: sldebug("vdp") starts a simulation debugging session for the model vdp.

    Data Types: char | string


    As an alternative to programmatic debugging, you can debug and analyze models in the Simulink Editor using similar functionality available in the Simulink Toolstrip. Using the Debug tab, you can:

    • Add breakpoints that pause simulation within a time step

    • Step from one major time step to the next

    • Step from one block output method to the next

    • Step into and out of atomic subsystems, model references, and Stateflow® charts

    • Add port value labels to display block output values for major time steps

    • View the execution order

    • Annotate the block diagram with sample time information

    To start a simulation debugging session interactively, add one or more breakpoints to your model and in the Breakpoints List, check that Pause within time step is selected. When the simulation pauses on a breakpoint, some of the programmatic debugging commands, such as the stop command, are available for use in the MATLAB Command Window.

    When you start a simulation debugging session interactively, the simulation pauses just before executing the first block output method.

    Version History

    Introduced in R2006a