Main Content

Log data to file

Option to log data that uses Dataset format to MAT or MLDATX file

Model Configuration Pane: Data Import/Export

Description

Specify whether to log simulation data that uses the Dataset format to a MAT or MLDATX file instead of logging to the workspace.

Log data to a MAT or MLDATX file by specifying the file extension as .mat or .mldatx. For example, to log data to an MLDATX file named myData, type myData.mldatx.

Logging data to an MLDATX file typically results in a smaller file size. The MLDATX file created when you select Log data to file is similar to a Simulation Data Inspector session file, but it contains only the data for a single run without view or comparison information.

This table shows the type of data that can be logged to each file type.

Logged DataFile Type
MAT fileMLDATX file
Output saved in Dataset formatYesYes
Signal logging dataYesYes
States saved in Dataset formatYesYes
Final states saved in Dataset formatYesNo
Data storesYesYes
Data logged using a Record blockNoYes
Data logged using a To Workspace blockNoYes
Data logged using a Scope block configured to log data to the workspaceNoYes

To log states or output data to a file, set the Save format parameter to Dataset.

To log Final states data to a MAT file, set the Save format parameter to Dataset and clear Save final operating point. MLDATX files do not support logging Final states data.

Settings

off (default) | on
off

Simulation data logged using the Dataset format logs to the workspace and does not log to a file.

on

Simulation data logged using Dataset format logs to a MAT or MLDATX file and does not log to the workspace. By default, data is saved in a MAT file with the name out.mat in the current working directory. To log data to an MLDATX file, change the file extension to .mldatx. To save the file in a different location or using a different filename, specify the path and filename in the text box.

Tips

  • When the data in the MAT file fits into memory, use the load function to access the data.

  • To access the data in an MLDATX file, use the Simulink.sdi.load to load the data. Then, use the Simulink.sdi.Run.getLatest function to get the Simulink.sdi.Run object associated with the loaded MLDATX file. To export the data to the workspace, use the export function.

    Simulink.sdi.load("out.mldatx")
    runObj = Simulink.sdi.Run.getLatest;
    dataset = export(runObj);
  • When the data in the MAT file is too large to fit into memory, access the data in the MAT file using Simulink.SimulationData.DatasetRef and matlab.io.datastore.SimulationDatastore objects.

  • To log data to file while running simulations with the simulation object, use the setModelParameter function.

    sm = simulation('model')
    sm = setModelParameter(sm,LoggingToFile='on')
    start(sm)

    You can log data to an MLDATX file with the simulation object only in normal mode simulations.

  • Except for parallel simulations, the software overwrites the contents of the file during each simulation unless you change the name of the file between simulations. For details, see Save Logged Data from Successive Simulations.

Note

To log data to an MLDATX file, in Preferences > Storage, make sure the default setting of View and record data is selected. If you select View during simulation only instead, the MLDATX file contains the logged signal name, but does not include the data.

Recommended Settings

The table summarizes recommended values for this parameter based on considerations related to code generation.

ApplicationSetting
DebuggingNo impact
TraceabilityNo impact
Efficiency

No recommendation

Safety precaution

No recommendation

Programmatic Use

Parameter: LoggingToFile
Value: 'on' | 'off'
Default: 'off'
Parameter: LoggingFileName
Type: string | character vector
Value: valid path and file name
Default: 'out.mat'

Version History

Introduced in R2016a

expand all