Log Data to Persistent Storage - MATLAB & Simulink (original) (raw)

When to Log to Persistent Storage

In some cases, logging simulation data can create large amounts of data that are too large for your computer to hold in working memory while also running efficiently. Such situations can include simulations that log many signals, simulations that run for a long time with many time steps, and parallel simulations. When your simulation configuration creates a large amount of data, you can log that data to persistent storage, rather than logging it to working memory.

You can store logged simulation data to persistent storage in a MAT file. You control logging to persistent storage at the model level. You can enable and disable the feature by changing one model configuration parameter () without changing the model layout.

If you use Dataset format for logging, you can log each of these kinds of data to persistent storage:

By default, logging to persistent storage is disabled, so that logged data is stored in the MATLAB® workspace. For most models, logging to the workspace is simpler because it avoids loading and saving logging files. Compared to accessing data logged to memory, accessing data logged to persistent storage requires some additional steps. For short simulations, logging to the MATLAB workspace can be faster and possibly use less memory than logging to persistent storage.

Limitations for Logging to Persistent Storage

Alternative Approaches for Reducing Logging Memory Usage

When you need to simulate a model that creates a large amount of data and you do not want to log the simulation data to persistent storage, consider using one of these alternatives.

Log to Persistent Storage

  1. Specify the kinds of logging to perform (for example, signal logging and output logging) and the variable names for the logging data.
  2. In the model diagram, mark selected signals for signal logging.
  3. Use Dataset format for logging the data. Data that is logged in any other format is stored in the workspace.
    • Signal logging and data store logging use Dataset format only. The default format for output, states, and final states logging isDataset.
    • For final states logging, clear the Save final operating point configuration parameter.
  4. Enable logging to persistent storage and specify an output MAT file name.
    • Select the configuration parameter.
    • Specify the MAT file to use. Do not use a file name from one locale in a different locale.
  5. To save the logged Dataset data using timeseries or timetable elements, set the Dataset signal format configuration parameter. The default format istimeseries. The timetable format is helpful for MATLAB combining logged data from multiple simulations. For details about thetimetable format, see Dataset signal format.
  6. Simulate the model.

Enable Logging to Persistent Storage Programmatically

You can programmatically log to persistent storage. To enable logging to persistent storage, use the LoggingToFile and LoggingFileName name-value pairs with either the sim command orset_param command.

To enable the logging approaches that you want to use, set these parameters to'on', as applicable:

To log output, states, and final states data to persistent storage, set theSaveFormat parameter to 'Dataset'.

To log final states data to persistent storage, set theSaveOperatingPoint to 'off'.

How Simulation Data Is Stored

Logging to persistent storage saves logged simulation data in the specified MAT file. The data is stored as a Simulink.SimulationData.Dataset objects for each type of logging that uses Dataset format. The Dataset elements are stored as either timeseries or timetable objects, depending on how you set the Dataset signal format parameter. For details about the timetable format, see Dataset signal format.

The Dataset object name in the file is the name of the variable that you used for logging. For example, if you use the default signal logging variablelogsout, the Dataset object in the MAT file islogsout.

Save Logged Data from Successive Simulations

The approach you use for saving data logged from successive simulations depends on whether you are performing parallel simulations.

Without Using Parallel Simulations

Each time you simulate a model without using parallel simulation, Simulink® overwrites the contents of the MAT file unless you change the name of the file between simulations. When you use aSimulink.SimulationData.DatasetRef object that references data in the MAT file to retrieve data in the file, it retrieves the most recent version of the data. To preserve data from an earlier simulation, use one of these approaches:

If you run multiple simulations that overlap in time, use a unique MAT file for each model that you log to persistent storage.

If you change the file name used for logging to persistent storage, then to access the logged data, use one of these approaches:

For details about using DatasetRef objects to access logged data, seeLoad Big Data for Simulations.

With Parallel Simulations

For parallel simulations, for which you specify an array of input objects, if you log to file, Simulink:

For more information about parallel simulations, see Running Multiple Simulations.

See Also

Functions

Model Settings

Topics