Main Content

Save Simulation Data

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

  • Output — Log output data to analyze signals connected to root-level Outport blocks.

  • Signal data — Log signal data to analyze a signal, bus, or array of buses connected to a block.

  • Time — Log time data to save time values for a simulation.

  • State or final state — Log state data to analyze how block states change throughout the simulation. Log model operating points during a simulation to resume the simulation from any of those operating points.

  • Data store — Log data stores to save the values of a local or global data store for all the steps in a simulation. Data store logging is commonly used for model debugging or confirming a model modification.

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.

GoalLogging TechniqueMore 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 name yout.

Output data logged in Dataset 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 file, an MLDATX file, or an Excel® file.

Visualize logged data in the Record 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.

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 log States. 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 name xFinal.

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 Use Model Operating Point for Faster Simulation Workflow.

Log data stores, which share data throughout a model hierarchy, to debug a model or confirm a model modification. Enable Data stores logging, add a Data Store Memory block to the model, and configure the block to log data.

Data stores are saved to the workspace using the default variable name dmsout.

Logged data stores stream to the Simulation Data Inspector during simulation.

For more information, see Log Data Stores.

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 DataData Format
DatasettimeseriesArrayStructure with TimeStructure
OutputYes (default)NoYesYesYes
Signal data using signal loggingYes (default)NoNoNoNo
Signal data using a Record blockYes (default)NoNoNoNo
Signal data using a To Workspace blockNoYes (default)YesYesYes
Signal data using a To File blockNoYes (default)YesNoNo
Signal data using a Scope blockYes (default)NoYesYesYes
States and final statesYes (default)NoYesYesYes
Data storesYes (default)NoNoNoNo

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:

  • In the block diagram, add blocks or mark signals as specified by your chosen technique.

  • Configure blocks to log data in the chosen format.

    • If using the Record block, a Scope block, or logging data stores, configure the blocks to log data.

    • If using the To Workspace, To File, or Scope block to log data, you can change the logged data format using the Block Parameters dialog box. Double-click a block to access the Block Parameters dialog box.

  • Configure the model to log the chosen data.

    1. In the Modeling tab, in the Setup section, click Model Settings.

    2. Select the Data Import/Export pane.

    3. Select parameters to save data. For example, to save output data, select Output.

The parameters you select depend on the data you log.

DataConfiguration ParameterEnabled by Default?

Output data

Output

Yes

Signal data marked for signal logging

Signal logging

Yes
Time data

Time

Yes

States

StatesNo
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, click Run 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

Related Topics