Main Content

Export Simulation Data

Exporting, or 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 perform other postprocessing on 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 analysis and postprocessing. Exporting data is also known as data logging or saving simulation data.

You can log data in several formats:

Consider converting data logged in other formats to Dataset format to simplify post-processing. For more information, see Dataset Conversion for Logged Data.

You can also use logged data as the input for simulating a model.

Logging Simulation Data

You can use one or more of these techniques to log simulation data.

Logging TechniqueUsageDocumentation

Enable output logging and 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.

Output

Outport

Enable signal logging and mark signals throughout the model for logging

Use signal logging to avoid adding blocks to your model.

Log signals using individual signal logging rates specified using the Signal Properties or Instrumentation Properties.

Data is available when simulation is paused or stopped or when the simulation completes.

Signal logging

Export Signal Data Using Signal Logging

Connect a signal to a Record block

You can use the Record block to log data to the workspace, to a file, or to both the workspace and a file.

The Record block supports logging data to a MAT file, a Microsoft® Excel® file, or to a MLDATX file.

You can visualize logged data in the Record block using several visualizations including sparklines plots, time plots, and XY plots.

Record, XY Graph

Connect a signal to a To Workspace block.

Specify the name of the variable that stores logged signal data.

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

To Workspace

Connect a signal to a To File block.

The To File block saves data to a MAT file instead of saving it to a variable in the workspace.

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

Use the MAT file only after the simulation has completed.

To File

Configure Simulink® to export time and state data.

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

States are logged at the base sample rate of the model.

Time

States

Save Block States and Simulation Operating Points

Data Format for Logged Simulation Data

Log data stores

Log a data store, which shares data throughout a model hierarchy, to capture the order of all data store writes.

Log Data Stores

Connect a Scope block to a signal.

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

Scopes store data and can be memory intensive.

Scope

Enable Simulation Data Export

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

  • Configure data to log using the Configuration Parameters dialog box. In the Modeling tab, under Setup click Model Settings. Then, select the Data Import/Export pane. For more information, see Model Configuration Parameters: Data Import/Export

  • Configure data to log programmatically using the set_param function.

  • Provide inputs to the sim function to configure data to log for a specific simulation. The configuration parameter values are applied during simulation and reverted at the end of simulation.

In each approach, 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 View Data in 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 timestamp sequences, 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. The difference in memory can be a critical performance factor, particularly when logging buses that contain thousands of elements.

Logging to Persistent Storage

You can encounter memory issues when you log many 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 final operating point parameter.

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

For details, see Log Data to Persistent Storage.

See Also

Blocks

Functions

Related Topics