Save logged simulation data in HDF5 file





simscape.logging.export(simlog,fileName) saves the simlog object, containing logged simulation data, for future use. You can use this function only for data logged with the Stream data to temporary disk directory preference turned on.

When you stream simulation data to disk, the data is stored as a simlog object in a temporary file, and the workspace logging variable references the simlog object. The temporary file persists as long as there is a logging variable in the workspace that references the file. This function lets you save the simlog object to a different file, specified by the fileName argument, in HDF5 format.


collapse all

To enable streaming data to disk, on the MATLAB® Toolstrip, click Preferences. In the left pane of the Preferences dialog box, select Simscape, then select the Stream data to temporary disk directory check box.

Open the Permanent Magnet DC Motor example model, which already has data logging enabled, and run the simulation:


During the simulation, logged data is streamed to disk, to a temporary HDF5 file. After the simulation, you see the simulation log variable simlog_ssc_dcmotor (as specified by the Workspace variable name model configuration parameter) in your current workspace:

simlog_ssc_dcmotor = 

  Node with properties:

              id: 'ssc_dcmotor'
     loggingMode: 'disk'
    MRRef_Torque: [1x1 simscape.logging.Node]
     Load_Torque: [1x1 simscape.logging.Node]
      DC_Voltage: [1x1 simscape.logging.Node]
        DC_Motor: [1x1 simscape.logging.Node]
            ERef: [1x1 simscape.logging.Node]
         Sensing: [1x1 simscape.logging.Node]
     MRRef_Motor: [1x1 simscape.logging.Node]

The loggingMode: 'disk' property of the simlog_ssc_dcmotor variable indicates that this variable points to the temporary file on disk, which contains the simulation data. The temporary file exists as long as the variable exists in your workspace, then it is deleted.

To save the logged simulation data for future use, type:


This command creates a file under C:\Work, named motor_run1.h5, and stores the logged simulation data in this file, in HDF5 format.

To retrieve the logged simulation data at a later time and associate it with a workspace variable, use the simscape.logging.import function.

Input Arguments

collapse all

Logged simulation data, specified as a Node object, with the loggingMode property set to 'disk'. You refer to the simlog object by the name of the corresponding simulation log workspace variable. You specify the name of the simulation log variable by using the Workspace variable name parameter in the Simscape pane of the Configuration Parameters dialog box.

File name and path, specified as a character vector. The function stores the simlog object in the specified file, in HDF5 format. The fileName character vector must include the .h5 extension. If you do not include the path, the file resides in the current working directory.

If the file already exists, the function overwrites it without a warning. However, if you import a node from a file, and then try to export it to the same file, a message informs you that in this case the file cannot be overwritten.

Example: 'C:\Work\motor_run1.h5'

Data Types: char

Introduced in R2016a

Was this topic helpful?