Main Content

export

Export data for signal in Simulation Data Inspector to workspace or file

Description

sigData = export(sig) exports the data for one or more signals in the Simulation Data Inspector to the workspace.

example

sigData = export(sig,startTime,endTime) exports to the workspace the portion of one or more signals within the interval defined by the start time startTime and the end time endTime.

export(___,Name=Value) exports one or more signals in the Simulation Data Inspector to the workspace or a file according to the options specified by one or more name-value arguments.

For most signals, you can choose to export the data to the workspace, a MAT file, or a Microsoft® Excel® file.

When the signal contains video data, you can export the signal to an MP4 file. Exporting a video signal to an MP4 file is not supported for Linux® operating systems.

Examples

collapse all

This example shows how to create a run in the Simulation Data Inspector, access the data, and export the signal data to a timeseries object in the workspace.

Simulate the model sldemo_fuelsys to create a run in the Simulation Data Inspector that contains the logged data.

sim('sldemo_fuelsys'); 

Use the Simulink.sdi.getCurrentSimulationRun function to access the run.

fuelRun = Simulink.sdi.getCurrentSimulationRun('sldemo_fuelsys');

Use the getSignalByIndex function to get the second signal in the Simulink.sdi.Run object.

sig = getSignalByIndex(fuelRun,2);

Export the signal data to the workspace using the export function.

ts = export(sig);

Input Arguments

collapse all

Signal to export, specified as a Simulink.sdi.Signal object or an array of Simulink.sdi.Signal objects.

Start of signal portion to export, specified as a numeric scalar.

Example: sigData = export(sig,0,10) exports to the workspace the portion of the signal sig between the times 0 and 10.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

End of signal portion to export, specified as a numeric scalar.

Example: sigData = export(sig,0,10) exports to the workspace the portion of the signal sig between the times 0 and 10.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: to="file",filename="mySpreadshee.xlsx"

Where to export data, specified as:

  • 'variable' — Export one or more signals to the workspace.

  • 'file' — Export one or more signals to a MAT file, a Microsoft Excel file, or an MP4 file.

    When you export data to a file, specify a file name using the filename name-value argument.

Example: to="file",filename="mySpreadsheet.xlsx"

Name and type of file to which to export data, specified as a string or character vector. Include a file extension to specify the type of file:

  • .mat — Export data to MAT file.

  • .xlsx — Export data to Microsoft Excel file.

  • .mp4 — Export data to MP4 file.

When you do not specify an extension with the file name, the data exports to a MAT file.

To specify the filename name-value argument, you must specify the to name-value argument as 'file'.

To export a video signal to an MP4 file:

  • The signal must be 2D or 3D and contain RGB or monochrome video data.

  • The data type for the signal values must be double, single, or uint8.

  • The signal must be represented as a single signal with multidimensional sample values.

    You may need to convert the representation of the signal using the collapse function before exporting the signal data. For more information, see Analyze Multidimensional Signal Data.

Example: to="file",filename="mySpreadsheet.xlsx"

Tips

  • When you export one signal to a MAT file, the data is saved in the MAT file as a timeseries object.

  • When you export multiple signals to a MAT file, the data is saved as a Simulink.SimulationData.Dataset object that contains a Simulink.SimulationData.Signal object for each exported signal.

  • Data exported to a Microsoft Excel file is saved using the format described in Microsoft Excel Import, Export, and Logging Format.

  • When you export data to a Microsoft Excel file, you can specify additional options using the overwrite, metadata, and sharetimecolumn name-value arguments.

Data to overwrite in existing Microsoft Excel file, specified as 'file' or 'sheetsonly'.

  • 'file' — Overwrite the entire file with the exported data.

  • 'sheetsonly' — Overwrite only sheets of the Microsoft Excel file that contain data that corresponds to the exported data.

Specify the overwrite name-value argument only when you export data to a Microsoft Excel file.

When you export data to an existing MAT file, the exported data overwrites the entire file.

Example: overwrite="sheetsonly"

Metadata to include in the exported Microsoft Excel file, specified as a string array. By default, the exported file does not include any metadata. You can export this metadata to a Microsoft Excel file:

  • dataType — Signal data type

  • units — Signal units

  • blockPath — Path to the source block for logged signals

  • interp — Signal interpolation method

  • portIndex — Index of the port on the source block for logged signals

The order of metadata options in the string array does not determine the order of the metadata in the exported file, which always matches the description in Microsoft Excel Import, Export, and Logging Format.

Example: metadata=["units" "dataType"]

Option for signals that have identical time data to share time columns in the exported Microsoft Excel file, specified as 'on' or 'off'. By default, signals that have identical time data share a time column in the exported file. When you specify the value as 'off', each signal in the exported file has its own time column.

Example: sharetimecolumn='off'

Output Arguments

collapse all

Exported signal data, returned as a timeseries object or a Simulink.SimulationData.Dataset object.

Alternatives

You can export data to the workspace or a file using the Simulation Data Inspector. For more information, see Save and Share Simulation Data Inspector Data and Views.

Version History

Introduced in R2017b