Main Content

Export Simulation Data

出口simula(日志)tion 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 several formats:

  • Simulink.SimulationData.Dataset

  • Array

  • Structure

  • Structure with time

  • MATLABtimeseries

  • ModelDataLogs

    Note

    TheModelDataLogsformat is supported for backward compatibility. Starting in R2016a, you cannot log data in theModelDataLogsformat. In R2016a or later, when you open a model from an earlier release that had usedModelDataLogsformat, the model logs data inDatasetformat.

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

You can also use exported data as the 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 Approach Usage Documentation

Connect aScopeblock to a signal.

If you use aScopeblock for viewing results during simulation, consider also using theScopeblock to export data.

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

Scopes store data and can be memory intensive.

Scope

Connect a signal to aTo Fileblock.

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 aTo Workspaceblock.

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

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

Outport

Set the signal logging properties for a signal.

Use signal logging to avoid adding blocks, such asScope,To File, andTo Workspaceblocks, to your model.

Log signals based on individual signal rates.

Data is available 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.

Use theOutputparameter to save rootOutportblock data during simulation.

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

Data Format for Logged Simulation Data

Specify Signal Values to Log

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 thesimcommand to log simulation data programmatically.

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

Select theReturn as single object当模拟usi的模型参数ng thesimcommand inside a function or aparforloop.

sim

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 theSimulation Data Inspector.

The Simulation Data Inspector has some limitations on the kinds of logged data that it displays. SeeView 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 performance can be a critical performance factor, particularly when logging bus signals that have thousands of bus 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 theConfiguration Parameters>Data Import/Exportpane, selectLog Dataset data to fileoption. Specify the kinds of logging (for example, signal logging and states logging).

  • For logging output and states data, set theFormatparameter toDataset.

  • If you select theFinal statesparameter, clear theSave final operating pointparameter.

使用一个Simulink.SimulationData.DatasetRefobject to access signal logging and states logging data loads data into the model workspace incrementally. Accessing data for other kinds of logging loads all the data at once.

For details, seeLog Data to Persistent Storage.

See Also

Blocks

Functions

Related Examples

More About