Save Simulation Data - MATLAB & Simulink (original) (raw)

Main Content

Saving, or logging, simulation data provides a baseline for analyzing and debugging a model. You can save simulation data to the workspace or a file. Once simulation data is logged, you can later retrieve, analyze, and postprocess the data without rerunning the simulation. You can also use logged data as the input for simulating a model.

To log simulation data:

  1. Choose the type or types of simulation data to log.
  2. Choose one or more logging techniques based on the data you want to log.
  3. Log the simulation data.

This flow chart provides an overview of the available techniques and necessary configuration settings based on the type of data you choose to log.

Flow chart for the available logging techniques and necessary configuration settings to log each data type.

Choose Type of Simulation Data to Log

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

Choose Technique to Log Simulation Data

The available logging techniques and necessary configuration settings depend on the type of simulation data you want to log. You can log any combination of simulation data types and use multiple logging techniques to save simulation data within the same model.

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

Goal Logging Technique More Information
Log output data. Enable Output logging and connect a signal to a root-level Outport block. Consider logging output data in a top-level model when your model already includes an Outport block. Logged output data is stored in the workspace with the default variable nameyout.Output data logged inDataset format streams to the Simulation Data Inspector during simulation.
Log signals throughout the model without adding blocks. Enable Signal logging and mark signals for logging. For more information, see Save Signal Data Using Signal Logging. Use signal logging to avoid adding blocks to your model.Signal logging data is stored in the workspace with the default variable name logsout.Signal logging streams data to the Simulation Data Inspector during simulation.Log signals using individual signal logging rates specified using the Signal Properties or Instrumentation Properties.Log subsets of marked signals programmatically or by using the Signal Logging Selector. For more information, see Override Signal Logging Settings.
Log signal data to the workspace, a file, and the Simulation Data Inspector. Connect one or more signals to a Record block and configure the block to record data to the workspace or a file. The Record block logs data to the workspace with the default variable name recordout.During simulation, the Record block streams data to the Simulation Data Inspector.You can configure the Record block to also log data to the workspace, a file, or both. For more information, see Log Data to the Workspace and a File Using the Record Block.The Record block supports logging data to a MAT, MLDATX, Excel®, or Parquet file.Visualize logged data in theRecord block using several visualizations including sparklines plots, time plot, and XY plots.
Log signal data to the workspace. Connect a signal to a To Workspace block. The To Workspace block logs data to the workspace with the default variable name simout.During simulation, the To Workspace block streams logged data to the Simulation Data Inspector.Save data at a sample rate other than the base sample rate.For more information, see Output Simulation Data with Blocks.
Log signal data to a MAT file. 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. When you configure the model to Record logged workspace data in Simulation Data Inspector, data logged to a To File block is available in the Simulation Data Inspector when the simulation is paused, stopped, or completes. Data cannot be streamed to the Simulation Data Inspector during simulation.Save data at a sample rate other than the base sample rate. The To File block does not support logging variable-size signals.For more information, see Output Simulation Data with Blocks.
Log signal data displayed in a Scope block. Connect one or more signals to a Scope and configure the block to log data to the workspace. Logged Scope data is saved to the workspace with the default variable name ScopeData.Data logged streams to the Simulation Data Inspector during simulation.Save data at a sample rate other than the base sample rate.Scope blocks store data and can be memory intensive.For more information, see Save Simulation Data Using Scope Block.
Log time values. Enable Time logging. The software logs time data to the workspace at the base sample rate of the model.Logged time data is saved to the workspace with the default variable name tout.
Log block state data to analyze how block states change throughout the simulation. Enable States logging or**Final states** logging. State data saved in Dataset format streams to the Simulation Data Inspector during simulation.To analyze how block states change throughout the simulation, configure the model to logStates. States data is saved to the workspace with the default variable name xout.To log a snapshot of block states when the simulation is paused or when the simulation stops, configure the model to log Final states. Final states data is saved to the workspace with the default variable namexFinal.For more information, see Save Block States and Simulation Operating Points.
Log a complete model operating point to use as the starting point for future simulations. Enable Final states logging and select Save final operating point. The model operating point represents the complete set of block states and the state of the model, including the simulation time, the solver state, and the execution engine state. For more information, see Save Block States and Simulation Operating Points.Use model operating points to save time by not repeatedly running segments of a simulation that do not change from one scenario to the next. For more information, see Speed Up Simulation Workflows by Using Model Operating Points.
Log data stores, which share data throughout a model hierarchy, to debug a model or confirm a model modification. Enable Data stores logging, add aData Store Memory block to the model, and configure the block to log data. Data stores are saved to the workspace using the default variable namedmsout.Logged data stores stream to the Simulation Data Inspector during simulation.For more information, see Log Data Stores.
Log all data that uses Dataset format to a MAT or MLDATX file. Select Log Dataset data to file and enter a filename. If you log all data in Dataset format to a MAT or MLDATX file, the software does not log that data to the workspace.Logged signals and data stores, as well as states and outputs in Dataset format, stream to the Simulation Data Inspector during simulation.

Choose Data Format

You can log data in several formats. This table shows the data formats available for each type of data and logging technique.

Logged Data Data Format
Dataset timeseries timetable Array Structure with Time Structure
Output Yes (default) Elements of a Dataset object can store logged data values as timeseries objects. Elements of a Dataset object can store logged data values as timetable objects. Yes Yes Yes
Signal data using signal logging Yes (default) Elements of a Dataset object can store logged data values as timeseries objects. Elements of a Dataset object can store logged data values as timetable objects. No No No
Signal data using a Record block Yes (default) Elements of the Dataset object store logged data values as timeseries objects. No No No No
Signal data using a To Workspace block No Yes (default) No Yes Yes Yes
Signal data using a To File block No Yes (default) No Yes No No
Signal data using a Scope block Yes (default) Elements of a Dataset object can store logged data values as timeseries objects. Elements of a Dataset object can store logged data values as timetable objects. Yes Yes Yes
States and final states Yes (default) Elements of a Dataset object can store logged data values as timeseries objects. Elements of a Dataset object can store logged data values as timetable objects. Yes Yes Yes
Data stores Yes (default) Elements of a Dataset object can store logged data values as timeseries objects. Elements of a Dataset object can store logged data values as timetable objects. No No No

Time data is logged as a vector of the simulation times. For more information about the data formats, see Data Format for Logged Simulation Data.

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

Log Data

Once you have chosen the types of data you want to log and chosen your logging technique, prepare the model to log data. Depending on the data and the chosen technique, use one or more of these steps:

The parameters you select depend on the data you log.

Data Configuration Parameter Enabled by Default?
Output data Output Yes
Signal data marked for signal logging Signal logging Yes
Time data Time Yes
States States No
Final states Final states No
Data stores Data stores Yes
Data logged in a format other than Dataset and data logged using To File or Scope blocks that you want to view in the Simulation Data Inspector after simulation pauses or stops. Record logged workspace data in Simulation Data Inspector No

Once you have prepared your model to log the chosen data, clickRun to simulate the model. Data is logged during simulation. To inspect logged simulation data interactively, consider using the Simulation Data Inspector. For more information, see View Simulation Data in Simulation Data Inspector.

You can also access data logged to the workspace programmatically. By default, results are returned as a single Simulink.SimulationOutput object that contains complete simulation metadata and all simulation data logged to the workspace. Each logged data type is a property of the SimulationOutput object specified by the variable name of the logged data. For more information, see View and Access Logged Simulation Data.

See Also

Model Settings

Objects

Blocks

Functions

Topics