Stateflow User's Guide Previous page   Next Page

Logging Data Values and State Activity

During simulation, you can log values for data and state activity into Simulink objects. After simulation, you can access these objects in the MATLAB workspace and use them to report and plot the values.

You can use the following procedure to learn how to access logged Stateflow data and state activity. This procedure uses the model, myModel, from the preceding topic, Setting Test Points for Stateflow States and Local Data with Model Explorer.

  1. If myModel is not already open, in the MATLAB Command Window prompt, type
  1. The model is displayed.

  1. In the Simulink window, right-click the Stateflow block and select Log Chart Signals.
  1. The Signal Logging dialog appears, as shown.

  1. Select the check box next to A.
  1. This is the state activity signal for state A. When A is active, its value is 1. When A is inactive, its value is 0.

    After checking A, notice the following properties in the right pane of the Signal Logging dialog:

    Signal Properties
    Description
    Signal Name
    Name of the highlighted state or data.
    Log signal data
    Checking this selects the highlighted signal in the Signals pane.
    Logging name
    Name of the signal logged. By default, this is set to the name of the selected/highlighted state or data. You can select Custom for this property to rename the selected/highlighted signal in the adjacent field to the right.
    Limit data points to last
    Select this property to enter the number of most recent sample values to log in the adjacent field to the right for the selected/highlighted signal.
    Decimation
    Select this property to enter the level of decimation for the signal values logged for the selected/highlighted signal.

  1. Select all the signals in the Signal pane and click OK to close the Signal Logging dialog.
  2. Simulate the model.
  1. During simulation, the Simulink model data log object logsOut is generated in the MATLAB workspace.

  1. After simulation, enter the following at the MATLAB prompt:
  1. You see the following result:

    The display identifies logsOut as a Simulink object of type ModelDataLogs. This is the highest level logging object. The object Chart1 appears as the only contents of logsOut. It represents logged data for the Stateflow block Chart1 and is identified as a Simulink object of type StateflowDataLogs.

  1. At the MATLAB prompt, enter the following:
  1. You see the following result:

    The signals that you selected in the Signal Logging dialog appear as Simulink objects of type Timeseries. Notice that the signals for the activity of state X and the value of data x appear as ('A.X') and ('A.X.x'), respectively. Because of the way that logged signals are stored for Stateflow, you need to use this notation to access logged data for Stateflow objects below chart level in the Stateflow diagram.

  1. At the MATLAB prompt, enter the following:
  1. You see the following result:

    The logging object for the data x, ('A.X.x'), is actually a structure of logged data pertinent to x. The actual logged signal values for x are contained in the Data object, a vector of 114 values. For example, if you were to enter the MATLAB command logsOut.Chart1.('A.X.x').Data, a long stream of data would appear. A better way to see the logged values of x is to use the plot method shown in the next step.

  1. At the MATLAB prompt, plot the values of x with the following command:
  1. You see the following result:

    The preceding plot exhibits the expected results for the value of x. It is incremented for 10 time steps before resetting to 0 when states X and A are exited and state B is entered in the Stateflow diagram.

The preceding example is a demonstration of some of the capabilities you have for reporting logged Stateflow data. Stateflow data conforms to the general rules for handling logging signals in Simulink. For more information on how you can use and manipulate logged data with commands and scripts in MATLAB, see Logging Signals in the Simulink documentation.


Previous page  Setting Test Points for Stateflow States and Local Data with Model Explorer Using a Floating Scope to Monitor Data Values and State Activity Next page

© 1994-2005 The MathWorks, Inc.