Main Content

Monitor Test Points in Stateflow Charts

This example shows you how to specify data or states as test points that you can plot with a floating scope or log to the MATLAB® base workspace during simulation.

About Test Points in Stateflow Charts

A Stateflow® test point is a signal that you can observe during simulation, for example, by using a Floating Scope block. You can designate states or local data with these properties as test points:

  • Size - scalar, one-dimensional, or two-dimensional

  • Type - any data type except ml

  • Location - descendant of a Stateflow chart

You can specify individual data or states as test points by setting their TestPoint property via the Stateflow API, in the Property Inspector, or in the Model Explorer.

You can monitor individual Stateflow test points with a floating scope during model simulation. You can also log test point values into MATLAB workspace objects.

You can also use active state output to view or log state activity data in Simulink®. For more information, see Monitor State Activity Through Active State Data.

Set Test Points for Stateflow States and Data with the Property Inspector

You can explicitly set individual states, local data, and output data as test points in the Model Explorer. The following procedure shows how to set individual test points for Stateflow states and data.

1. Open the model.

In the Stateflow chart, state A and its substate X are entered on the first tic event. State A and substate X stay active until 10 tic events have occurred, and then state B is entered. On the next event, state A and substate X are entered and the cycle continues. The data data belongs to substate X. The entry and during actions for substate X increment data while X is active for 10 tic events. When state B is entered, data reinitializes to zero, and then the cycle repeats.

2. Open the Property Inspector. In the Modeling tab, select Property Inspector.

3. Select state A. Then, in the Logging section of the Property Inspector, select Test Point.

4. Repeat this for state X and B.

5. Open the Symbols pane. In the Modeling tab, select Symbols Pane.

6. In the Symbols pane, select the data data. Then, in the Logging section of the Property Inspector, select Test Point.

You can also log these test points. For instructions, see Log Multiple Signals.

Monitor Data Values and State Self Activity Using a Floating Scope

In this section, you configure a Floating Scope block to monitor a data value and the self activity of a state.

1. Open the model.

2. Double-click the Floating Scope block.

3. In the Floating Scope window, select Simulation > Signal Selector. The Simulink canvas changes to selection mode.

4. From the canvas, select the chart. In the Connect pop-up window, select the signals.

5. To exit selection mode, click the X in the upper-right corner of the canvas.

5. Simulate the model.

When state A.X is active, the signal value is 1. When that state is inactive, the signal value is 0. Because this value can be very low or high compared to other data, you might want to add a second Floating Scope block to compare the activity signal with other data.

Related Topics