Export Simulation Data

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."

If you have data logged in different formats:

  • Array

  • Structure

  • Structure with time

  • MATLAB timeseries

  • ModelDataLogs

Consider converting this data to the Dataset format. This can simplify the post-processing of data. For more information, see Data Set 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 very often involves exporting signal data. You can use a variety of 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.

Consider exporting this data to capture complete information about the simulation as a whole.

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

Data Format for Exported 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 outputs of a model to the MATLAB base workspace during simulation of the model, use one of these interfaces:

In both approaches, specify:

View Logged Simulation Data With the 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

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 time stamp, the length of the interval (time step), and the total number of time stamps.

  • When multiple signals use identical sequences of time stamps, the signals share a single stored time stamp sequence. This may 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.

Was this topic helpful?