Watch Stateflow Data Values

Watch Data in the Stateflow Breakpoints and Watch Data Window

In the Watch Data tab of the Stateflow® Breakpoints and Watch Data window, you can view current data values when simulation pauses. The Watch Data tab displays a list of watch data, and highlights the values that changed since the last time simulation paused. To add Stateflow data to the watch data list:

  1. In the chart, right-click an object that uses the data.

  2. Select Add to Watch.

  3. Choose the data.

To add active state output and truth table data to the watch data list, from the Model Explorer, open the Data Properties dialog box. Select Add to watch window.

You can choose the display format for each data type. For more information, see Format Watch Data Display.

Watch Data in the Stateflow Chart

During simulation you can hover over objects in the chart to view the value of data used by the selected object. Hovering over objects in the chart provides the following information:

For:Tooltip Shows:
States and transitionsValues of data used by the object
Graphical, truth table, and MATLAB functionsValues of local data, and of inputs and outputs in the scope of the function

For example, the following chart stops execution before entering the Debounce state. Hovering over the transition from the Normal state to the On state shows that the value of sw is 3.6333.

Because the value of sw is greater than zero, the chart takes the transition from Normal to enter the Debounce state.

Watch Stateflow Data in the MATLAB Command Window

When simulation reaches a breakpoint, you can view the values of Stateflow data in the MATLAB® Command Window. In the following chart, a default transition calls a MATLAB function:

A breakpoint is set at the last executable line of the function:

function stats(vals)
%#codegen

% calculates a statistical mean and standard deviation
% for the values in vals.

len = length(vals);
mean = avg(vals, len);
stdev = sqrt(sum(((vals-avg(vals,len)).^2))/len);
coder.extrinsic('plot');
plot(vals,'-+');  % Breakpoint set at this line

When simulation reaches the breakpoint, you can display Stateflow data in the MATLAB Command Window.

  1. At the MATLAB prompt, press Enter.

    A debug>> prompt appears.

  2. Type whos to view the data that is visible at the current scope.

  3. Enter the name of data array vals at the prompt to display its value.

  4. Enter vals(2:3) to view specific values of that array.

The Command Line Debugger provides these commands during simulation:

Command

Description

dbstep

Advance to next executable line of code.

dbstep [in/out]

When debugging MATLAB functions in a chart:
  • dbstep [in] advances to the next executable line of code. If that line contains a call to another function, execution continues to the first executable line of the function.

  • dbstep [out] executes the rest of the function and stops just after leaving the function.

dbcont

Continue execution to next breakpoint.

dbquit (ctrl-c)

Stop simulation of the model. Press Enter after this command to return to the command prompt.

help

Display help for command-line debugging.

print var

...or...

var

Display the value of the variable var.

var (i)Display the value of the ith element of the vector or matrix var.
var (i:j)Display the value of a submatrix of the vector or matrix var.

save

Saves all variables to the specified file. Follows the syntax of the MATLAB save command. To retrieve variables in the MATLAB base workspace, use the load command after simulation has ended.

whos

Display the size and class (type) of all variables in the scope of the halted MATLAB function in your chart.

You can issue any other MATLAB command at the debug>> prompt but the results are executed in the Stateflow workspace. For example, you can issue the MATLAB command plot(var) to plot the values of the variable var.

To issue a command in the MATLAB base workspace at the debug>> prompt, use the evalin command with the first argument 'base' followed by the second argument command string, for example, evalin('base','whos').

    Note:   To return to the MATLAB base workspace, use the dbquit command.

Was this topic helpful?