Export Simulation Data

Exporting (logging) simulation data provides a baseline for analyzing and debugging a model. Use standard or custom MATLAB® functions to generate simulated system input signals and to graph, analyze, or otherwise postprocess the system outputs.

Simulation Data

Simulation data can include any combination of signal, time, output, state, and data store logging data.

Exporting simulation data involves saving signal values to the MATLAB workspace or to a MAT-file during simulation for later retrieval and postprocessing. Exporting data is also known as "data logging" or "saving simulation data."

You can have data logged in different formats:

  • Array

  • Structure

  • Structure with time

  • MATLAB timeseries

  • ModelDataLogs

      Note:   The ModelDataLogs class is supported for backwards compatibility. Starting in R2016a, you cannot log data in the ModelDataLogs format. Signal logging uses the Dataset format. In R2016a or later, when you open a model from an earlier release that had used ModelDataLogs format, the model simulated in use Dataset format.

Consider converting this data to the Dataset format, which can simplify the post-processing of data. For more information, see Dataset Conversion for Logged Data.

You can also import the exported data to use as input for simulating a model.

Approaches for Exporting Signal Data

Exporting simulation data often involves exporting signal data. You can use various approaches for exporting signal data.

Export ApproachUsage Documentation

Connect a Scope block or viewer to a signal.

If you use a Scope block for viewing results during simulation, consider also using the Scope block to export data.

Save output at a sample rate other than the base sample rate.

Scopes store data and can be memory intensive.


Connect a signal to a To File block.

Consider using a To File block for exporting large amounts of data.

Save output at a sample rate other than the base sample rate.

Use the MAT-file only after the simulation has completed.

To File

Connect a signal to a To Workspace block.

Document in the diagram the workspace variables used to store signal data.

Save output at a sample rate other than the base sample rate.

To Workspace

Connect a signal to a root-level Outport block.

Consider using this approach for logging data in a top-level model, if the model already includes an Outport block.


Set the signal logging properties for a signal.

Use signal logging to avoid adding blocks.

Log signals based on individual signal rates.

Data is available only when simulation is paused or completed.

Use signal logging to log array of buses signals.

Export Signal Data Using Signal Logging

Configure Simulink® to export time, state, and output data.

To capture complete information about the simulation as a whole, consider exporting this data.

Outputs and states are logged at the base sample rate of the model.

Data Format for Logged Simulation Data

Limit Amount of Exported Data

Samples to Export for Variable-Step Solvers

Log a data store.

Log a data store to share data throughout a model hierarchy, capturing the order of all data store writes.

Log Data Stores

Use the sim command to log simulation data programmatically.

Use sim to export to one data object the time, states, and signal simulation data.

Select the Return as single object parameter when simulating the model using the sim command inside a function or a parfor loop.


Enable Simulation Data Export

To export the states and root-level output ports of a model to the MATLAB base workspace during simulation of the model, use one of these interfaces:

In both approaches, specify:

View Logged Data Using Simulation Data Inspector

To inspect exported simulation data interactively, consider using the Simulation Data Inspector.

The Simulation Data Inspector has some limitations on the kinds of logged data that it displays. See Limitations of the Simulation Data Inspector.

Memory Performance

Optimization for Logged Data

When exporting simulation data in a simulation mode other than Rapid Accelerator, Simulink optimizes memory usage in the following situations.

  • When time steps happen at regular intervals, Simulink uses compressed time representation. Simulink stores the value for the first timestamp, the length of the interval (time step), and the total number of timestamps.

  • When multiple signals use identical sequences of timestamps, the signals share a single stored timestamp sequence. Sharing a single stored timestamp can reduce memory use for logged data by as much as a factor of two. An example when this memory performance can be a critical performance factor is when logging bus signals that have thousands of bus elements.

Logging to Persistent Storage

You can encounter memory issues when you log a large number of signals in a long simulation that has many time steps. Logging to persistent storage can address this kind of memory issue.

To log to persistent storage, in the Configuration Parameters > Data Import/Export pane, select Log Dataset data to file option. Specify the kinds of logging (for example, signal logging and states logging).

  • For logging output and states data, set the Format parameter to Dataset.

  • If you select the Final states parameter, clear the Save complete SimState in final state parameter.

Using a Simulink.SimlationData.DatasetRef object to access signal logging and states logging data loads data into the model workspace incrementally. Accessing data for other kinds of logging loads all of the data at once.

For details, see Log Data Using Persistent Storage.

See Also



Related Examples

More About

Was this topic helpful?