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:
Array
Structure
Structure with time
MATLABtimeseries
ModelDataLogs
Note
The
ModelDataLogs
format is supported for backward compatibility. Starting in R2016a, you cannot log data in theModelDataLogs
format. In R2016a or later, when you open a model from an earlier release that had usedModelDataLogs
format, the model logs data inDataset
format.
Consider converting data logged in other formats toDataset
format 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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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. |
|
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 |
Use Select theReturn as single object当模拟usi的模型参数ng the |
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:
Configuration Settings>Data Import/Exportpane (for details, seeModel Configuration Parameters: Data Import/Export)
sim
command
In both approaches, specify:
The kinds of simulation data that you want to export:
Signal logging
Time
Output
State or final state
Data store
Each kind of simulation data export has an associated default variable. You can specify your own variables for the exported data.
The characteristics of the logged data, including:
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 to
Dataset
.If you select theFinal statesparameter, clear theSave final operating pointparameter.
使用一个Simulink.SimulationData.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 the data at once.
For details, seeLog Data to Persistent Storage.
See Also
Blocks
Functions
Related Examples
- Load Data Logged In Another Simulation
- Data Format for Logged Simulation Data
- Specify Signal Values to Log
- Log Data to Persistent Storage