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 Data | File Type | |
---|---|---|
MAT file | MLDATX file | |
Output saved in
Dataset format | Yes | Yes |
Signal logging data | Yes | Yes |
States saved in
Dataset format | Yes | Yes |
Final states
saved in Dataset format | Yes | No |
Data stores | Yes | Yes |
Data logged using a Record block | No | Yes |
Data logged using a To Workspace block | No | Yes |
Data logged using a Scope block configured to log data to the workspace | No | Yes |
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 nameout.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 theSimulink.sdi.Run.getLatest
function to get theSimulink.sdi.Run
object associated with the loaded MLDATX file. To export the data to the workspace, use theexport
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
andmatlab.io.datastore.SimulationDatastore
objects.To log data to file while running simulations with the
simulation
object, use thesetModelParameter
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.
Application | Setting |
---|---|
Debugging | No impact |
Traceability | No 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' |