Main Content

Set Conditional Breakpoints for Stepping a Simulation

A conditional breakpoint is triggered based on a specified expression evaluated on a signal. When the breakpoint is triggered, the simulation pauses.

Set conditional breakpoints to stop Simulation Stepper when a specified condition is met. One example of a use for conditional breakpoints is when you want to examine results after a certain number of iterations in a loop.

Simulation Stepper allows you to set conditional breakpoints for scalar signals. These breakpoints appear for signals:

BreakpointDescription
Enabled breakpoint. Appears when you add the conditional breakpoint.
Enabled breakpoint hit. Appears when the simulation reaches the condition specified and triggers the breakpoint.
Disabled breakpoint. Appears when you disable a conditional breakpoint.
Invalid breakpoint. Appears when the software determines that a breakpoint is invalid for the signal. An enabled breakpoint image changes to this one when, during simulation, the software determines that the conditional breakpoint is invalid.

When setting conditional breakpoints, keep in mind that:

  • When simulation arrives at a conditional breakpoint, simulation does not stop when the block is executed. Instead, simulation stops after the current simulation step completes.

  • You can add multiple conditional breakpoints to a signal line.

Setting Conditional Breakpoints

To add the breakpoints:

  • Simulate the model.

  • Select the signal or the block for which you want to add a breakpoint.

  • In the Debug tab of the Simulink toolstrip, click Add Breakpoint. You can enter the conditions in the dialog box that appears.

    Add Conditional Breakpoint dialog box

Breakpoint List

The Breakpoint List displays all the breakpoints that you set in the model. To open the Breakpoints List, in the Debug tab of the Simulink Toolstrip, click Breakpoints List. The list opens at the bottom in the Simulink Editor.

Breakpoint list in Simulink Editor

The Breakpoint List contains the following columns:

  • Source – Path to the model element for which the breakpoint is set. Selecting the name of the breakpoint highlights the specific element location in the model

  • Enabled – Check box to indicate if the breakpoint is enabled or disabled. You can use the

    Enable/Disable breakpoints icon

    button on the top to enable or disable breakpoints.

  • Source Type – String that indicates the breakpoint type, such as Signal for conditional breakpoints or onStateEntry (During/Exit) for Stateflow® state breakpoints.

  • Condition – If applicable, an editable field describing the condition of a conditional breakpoint . This column is empty for unconditional breakpoints.

  • Hits – Number of times the breakpoint is hit during a simulation. Hits restart at 0 for any subsequent simulations.

The Delete breakpoints button allows you to delete a selected breakpoint. The drop-down arrow next to the button also gives an option of deleting all the breakpoints together. The Open Stateflow breakpoint and watch list button opens the Stateflow breakpoint and watch list. For more information on Stateflow breakpoints, see . (Stateflow)

For signal breakpoints, when a breakpoint is hit, the icon on the signal displays a green play button. . The model is in a paused state. The relevant breakpoint row is highlighted in light green.

Add and Edit Conditional Breakpoints Through Right-Click

  1. In a model, right-click a signal and select Add Conditional Breakpoint.

  2. In the Add Conditional Breakpoint dialog box, from the drop-down list, select the condition for the signal. For example, select greater than or less than.

  3. Enter the signal value where you want simulation to pause and click OK. For the condition values:

    • Use numeric values. Do not use expressions.

    • Do not use NaN.

    The affected signal line displays a conditional breakpoint icon:.

  4. Click the breakpoint to view and edit all conditions set for the signal.

  5. Simulate the model and notice that the model pauses as simulation steps through the conditional breakpoints.

Conditional Breakpoints Limitations

  • You can set conditional breakpoints only on real scalar signals of these data types:

    • double

    • single

    • int

    • bool

    • fixed point (based on the converted double value)

  • You cannot set conditional breakpoints (or port value display labels) on non-Simulink® signals, such as Simscape™ or SimEvents® signals.

  • Conditional breakpoints also have the limitations that port value display have (Port Value Display Limitations).

  • Conditional Breakpoints only work on the first iteration of For Each Subsystems

Observe Conditional Breakpoint Values

To observe a conditional breakpoint value of a block signal, use data tips to display block port values. You can add data tips before or after you add conditional breakpoints.

  1. Enable the value display for a signal. Right-click the signal line that has a conditional breakpoint and select Show Value Label of Selected Port.

    The data tip for the value display appears.

  2. Simulate the model and observe the conditional breakpoint and data tip when the simulation triggers the breakpoint.

Related Examples

More About