# Guy and Seth on Simulink

## New options for debugging in R2012b

Today I want to highlight R2012b features very useful when debugging a model.

Using the simulation stepping and conditional breakpoints, you should be able to run your simulation up to a certain point and move back and forth in time around this point to test things without re-running the entire simulation.

Simulation Stepper

You probably noticed that the Simulink toolbar now has 2 new buttons to step forward and backward:

To use this feature efficiently, I think it is important to understand how it works.

On one side, the next step button is obvious. Pushing it makes the simulation move forward by one step.

Moving backward involves a bit more. Just like with your DVR (or VCR as I first wrote), to go backward data must be recorded. Under the hood, the simulation stepper saves snapshots of the simulation using SimState.

When you click the previous step button for the first time, a dialog opens:

In this dialog, you can specify how many previous snapshots are saved and the number of major steps between those snapshots. Based on the size of your model, you need to choose numbers that avoid using too much memory or saving snapshots too frequently that might slow down your simulation.

Breakpoints

Before stepping backward, you first need to run and then pause the simulation. This can be done with breakpoints.

To pause at a specific simulation time, you can use the dialog shown above.

What is more interesting is to break based on signals values. When you right-click on a signal line, you can add conditional breakpoints:

You define the conditions for the breakpoint:

Of course, you can add multiple conditions for the same signal. Once you added all your breakpoints, you can manage them by clicking on the breakpoint icon next to the line:

Look at the documentation for a detailed example of Stepping Through a Simulation and let us know what you think of this new debugging technique by leaving a comment here.

### One Response to “New options for debugging in R2012b”

1. Han Geerligs replied on :

Hello all,

I’d like to mention an Enhancement Request I recently made. My proposal is to enable the user to be able to move backward/forward a spoecified amount of time instead of steps.

– Han

 Name (required) E-mail (required, will not be published) Website (optional) Spam protection (required): What is 6 + 8 ?

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>


If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).

Guy Rouleau and Seth Popinchalk are Application Engineers for MathWorks. They write here about Simulink and other MathWorks tools used in Model-Based Design.

These postings are the author's and don't necessarily represent the opinions of MathWorks.