Main Content

Analyze Big Data from a Simulation

To access data logged to a MAT-file for analysis in MATLAB®, use references to the data in the MAT-file.

Create DatasetRef Objects to Access Logged Datasets

When you log to a MAT-file, Simulink® stores a Simulink.SimulationData.Dataset object in the specified MAT-file. The elements of the Dataset object in the file are Dataset objects. There is one Dataset object for each set of logged simulation data. For example, a file may contain a Dataset object that contains a Dataset object for logged signal data and another Dataset object for logged states data.

To access simulation Dataset format data for a set of logged simulation data, create Simulink.SimulationData.DatasetRef objects. You can access individual elements of the dataset using a DatasetRef object. For details, see Load Individual Signals from a DatasetRef Object.

Use SimulationDatastore Objects to Access Signal Data

To access leaf signals in a logged Dataset object, create a matlab.io.datastore.SimulationDatastore object for the signal, based on the DatasetRef object for the Dataset object that contains the signal. For details, see

Stream Individual Signals Using SimulationDatastore Objects.

You can operate on data referenced by a SimulationDatastore object. For example, you can get the data in a chunk to be read into memory from the MAT-file. For an example, see matlab.io.datastore.SimulationDatastore.

Create Timetables for MATLAB Analysis

When you read a SimulationDatastore object, using the read or readall method the output is in MATLAB timetable format. For details about the timetable format, see Dataset signal format.

You can use a SimulationDatastore object to create a timetable for the signal values and read a timetable object with in-memory data. For example, for SimulationDatastore object dst1:

tt = dst1.Values.read;
ttt = tall(dst1.Values);

Create Tall Timetables

You can create a tall timetable:

mapreducer(0);
ttt = tall(dst1.Values);

Access Persistent Storage Metadata

If you use persistent storage for several simulations, you can have multiple MAT-files. When you run multiple simulations using batch processing, you get multiple MAT-files if you specify a different persistent storage MAT-file for each simulation. For parallel simulations, Simulink produces a separate MAT-file for each simulation run. To help you identify and understand the context of the simulation data included in a MAT-file, Simulink stores metadata about logging to persistent storage.

A Simulink.SimulationMetadata object includes in its ModelInfo structure a LoggingInfo structure with two fields:

  • LoggingToFile — Indicates whether logging to persistent storage is enabled ('on' or 'off')

  • LoggingFileName — Specifies the resolved file name for the persistent storage MAT-file (if LoggingToFile is 'on').

The MAT-file used for persistent storage contains a SimulationMetadata variable that stores the same simulation metadata as the Simulink.SimulationMetadata object. The SimulationMetadata is a system-generated name, not a variable name that you specify.

To access the persistent logging storage metadata, use one of these alternatives:

  • View simulation metadata by using the SimulationOutput object SimulationMetadata property.

  • Use tab completion to access SimulationMetadata object properties such as ModelInfo and to access field names.

  • Display simulation metadata in the Variable Editor. Click the SimulationOutput object and use one of these approaches:

    • Select the Explore Simulation Metadata check box (which displays the data in a tree structure).

    • Double-click the SimulationMetadata row.

Access Error Information

You can view error message and information about the stack and causes for simulation data by using the SimulationOutput object ErrorMessage property. For parallel simulations, if you are logging to file, Simulink enables the CaptureErrors argument for simulation.

See Also

Functions

Model Settings

Related Topics