| Stateflow User's Guide | ![]() |
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.
After checking A, notice the following properties in the right pane of the Signal Logging dialog:
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.
ans = Simulink.StateflowDataLogs (Chart1): Name Elements Simulink Class ('A.X.x') 1 Timeseries A 1 Timeseries ('A.X') 1 Timeseries B 1 Timeseries
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.
ans = Name: 'A.X.x' BlockName: 'StateflowChart/A.X.x' PortIndex: 1 SignalName: 'A.X.x' ParentName: 'A.X.x' TimeInfo: [1x1 Simulink.TimeInfo] Time: [114x1 double] Data: [114x1 double]
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.
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.
| Setting Test Points for Stateflow States and Local Data with Model Explorer | Using a Floating Scope to Monitor Data Values and State Activity | ![]() |
© 1994-2005 The MathWorks, Inc.