Log Simulation Output for States and Data
Logging data can help you troubleshoot chart design issues, examine data from your simulation, or postprocess the data without rerunning the simulation. You can log values for local, output, and active state data into a Simulink.SimulationData.Dataset
object. After you simulate the Simulink® model, you can access this object through the Simulation Data Inspector (Simulink).
For example, open the sf_yoyo
model. This model represents the control system of a tethered satellite. For more information about the model, see Yo-Yo Control of Satellites.
Enable and Customize Signal Logging
Signal logging is enabled by default. To enable, disable, or customize signal logging:
Open the Configuration Parameters dialog box.
In the Data Import/Export pane, select or clear Signal logging. For more information, see Signal logging (Simulink).
Optionally, specify a custom name for the signal logging object. The default name is
logsout
. This parameter specifies the name of the MATLAB® workspace variable that stores the logging data. For more information, see Save Signal Data Using Signal Logging (Simulink).Optionally, select a signal logging format using the Save format parameter. For more information, see Time, State, and Output Data Format (Simulink).
Configure States and Data for Logging
You can set logging properties for states, local data, and output data from inside the chart or programmatically from the command line.
Log Individual States and Data
You can configure logging properties for one state or data object at a time by using the Property Inspector for the state or data object. For more information, see Logging Properties.
Open the chart and select the
ReelMoving
state.in the Property Inspector, under Logging, click Log self activity.
By default, the logging name for this state is
Active.ReelMoving
. To assign a shorter name, set Logging Name toCustom
and enterReelMoving
.
To log multiple signals simultaneously, hold shift and select the states you want to log. A signal logging badge appears on each state that has logging enabled.
Monitor Data by Adding an Output Port
You can add an output port to a chart, and then use a Scope block to log and visualize the chart activity. For more information on monitoring chart activity, see Monitor State Activity Through Active State Data.
In the Simulation tab, click Add Output Port. In the top model, a new port titled ChartMode appears on the Chart block.
From the Simulink Sinks library, add a Scope (Simulink) block.
Connect the new output port to the Scope block.
Access Signal Logging Data
During simulation, Stateflow saves logged data in a Simulink.SimulationData.Dataset
signal logging object.
After running a simulation, you can view the logged data in the Simulation Data Inspector, Logic Analyzer, or in the MATLAB workspace.
View Logged Data Through the Simulation Data Inspector
You can use the Simulation Data Inspector to view and compare data across simulations. To open the Simulation Data Inspector, in the Simulation tab, click Data Inspector. When you simulate the model, the Simulation Data Inspector icon changes color to indicate new simulation data. For more information, see View State Activity by Using the Simulation Data Inspector.
Log Multidimensional Data
Stateflow logs each update to a multidimensional signal as a single change. For example, updating two elements of a matrix A
separately produces two different changes in the logged data:
A[1][1] = 1; A[1][2] = 1;
In contrast, updating a matrix A
in a single command produces a single change in the logged data, even though the command implies A[i][j] = 1
for all values of i
and j
:
A = 1;
Limitations
When simulating models in external mode, logging Stateflow data is not supported.
If you log state activity or data from a chart with Fast Restart enabled, any run after the first run duplicates the first logged data points. When you run algorithms that process these data points, you must account for this duplication.
See Also
Objects
Simulink.SimulationData.Dataset
(Simulink) |Stateflow.SimulationData.Data
|Stateflow.SimulationData.State
Functions
Tools
- Simulation Data Inspector (Simulink) | Signal Properties (Simulink)