Contenido principal

export

R2026b

Export run or signal from the Simulation Data Inspector to workspace or file

Description

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

example

data = export(sig,startTime,endTime) exports data within the time interval defined by startTime and endTime.

Specifying a time interval to export is not supported when exporting data to a Parquet file or VCD file.

data = export(runObj) exports the Simulink.sdi.Run object runObj to the base workspace as a Simulink.SimulationData.Dataset object. If you do not have a Simulink.sdi.Run object, you can either create one or use the run ID with Simulink.sdi.exportRun instead.

example

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

For most signals, you can use name-value arguments to specify whether to export the data to the workspace, a MAT file, a Microsoft® Excel® file, an MLDATX file, a Parquet file (since R2026a), CSV file (since R2026b), or a VCD file (since R2026b). 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.

example

Examples

collapse all

To access the Run object for the run in the Simulation Data Inspector that you want to export, use one of these functions:

For example, get the Run object for the most recent simulation of myModel.

runObj = Simulink.sdi.getCurrentSimulationRun("myModel");

To export the run data to a Simulink.SimulationData.Dataset object in the workspace, use the export function.

ds = export(runObj);

To export signal data from the Simulation Data Inspector to a timeseries object in the workspace, access the Simulink.sdi.Signal object. You can access the Signal object using the Simulink.sdi.Run object for the run that contains the signal, or by using the signal ID. For example, suppose you run a simulation and log data for a model named myModel.

To access the Run object for the most recently completed simulation of myModel, use Simulink.sdi.getCurrentSimulationRun.

myRunObj = Simulink.sdi.getCurrentSimulationRun("myModel");

To access the Signal object using the Run object, use getAllSignals, getSignalByIndex, or getSignalsByName. For example, get the second signal in the Run object.

mySigObj = getSignalByIndex(myRunObj,2);

Export the signal data to the workspace as a timeseries object.

ts = export(mySigObj);

To export run or signal data to a file, specify the To and Filename name-value arguments. The file extension determines the file type.

For example, export the data from the most recent simulation of myModel to a Microsoft Excel file.

runObj = Simulink.sdi.getCurrentSimulationRun("myModel");
export(runObj,To="file",Filename="myRunData.xlsx")

Input Arguments

collapse all

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

When you export one signal, the Simulation Data Inspector stores the data in a timeseries object. To export data from multiple signals to one workspace variable, create an array of Simulink.sdi.Signal objects corresponding to the signals that you want to export. The Simulation Data Inspector exports multiple signals to a Simulink.SimulationData.Dataset object in the workspace.

Example: data = export([sigObj1 sigObj2])

Start of time interval to export, specified as a nonnegative number less than endTime.

Specifying a time interval to export is not supported when exporting data to a Parquet file or VCD file.

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

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

End of time interval to export, specified as a nonnegative number greater than startTime.

Specifying a time interval to export is not supported when exporting data to a Parquet file or VCD file.

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

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

Run with data to export, specified as a Simulink.sdi.Run object.

Name-Value Arguments

expand all

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.

Example: Simulink.sdi.exportRun(runID,To="file",Filename="myFile.mat")

Export to File

expand all

Where to export data, specified as one of these options:

  • "variable" — Export one or more signals to a workspace variable.

  • "file" — Export one or more signals to a MAT file, a Microsoft Excel file, an MP4 file, an MLDATX file, a Parquet file (since R2026a), CSV file (since R2026b), or a VCD file (since R2026b).

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

    When you export a run to a MAT file, the data is saved in a Simulink.SimulationData.Dataset object. When you export more than one run to a MAT file using the Simulink.sdi.exportRun function, the data is saved in a Dataset object, where each element is a Dataset object that contains the data for one exported run.

Example: export(mySig,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 — MAT file

  • .mldatx — MLDATX file

  • .xlsx — Microsoft Excel file

  • .mp4 — MP4 file

  • .parquet — Parquet file (since R2026a)

  • .csv — CSV file (since R2026b)

  • .vcd — VCD file (since R2026b)

When you do not specify an extension with a 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: export(mySig,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.

  • When you export data to a Parquet file, you can configure shared or individual time columns, set row groups by height or size, and choose the compression used when saving the file using the Parquet File Options name-value arguments.

  • Data exported to a Parquet file is saved using the format described in Parquet File Format for Simulation Data.

  • When you export data to a CSV file, you can specify additional options using the Metadata and ShareTimeColumn name-value arguments. (since R2026b)

  • Data exported to a CSV file is saved using the format described in CSV File Format for Simulation Data (since R2026b)

Shared Options

expand all

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

  • 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: export(mySig,To="file",Filename="mySpreadsheet.xlsx",Metadata=["units" "dataType"])

Option for signals that have identical time data to share time columns in the exported 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.

Specify the ShareTimeColumn name-value argument only when you export data to a Microsoft Excel file, CSV file, or Parquet file.

Example: export(mySig,To="file",Filename="mySpreadsheet.xlsx",ShareTimeColumn="off")

Microsoft Excel File Options

expand all

Data to overwrite in existing Microsoft Excel file, specified as one of these options:

  • "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, Parquet file, CSV file, or VCD file, the exported data overwrites the entire file.

Example: Overwrite="sheetsonly"

Parquet File Options

expand all

Since R2026a

Option to generate JSON sidecar that contains all the logged metadata, specified as "on" or "off". Specify the ParquetMetadata name-value argument only when you export data to a Parquet file.

Since R2026a

Parquet file compression, specified as one of these options:

  • "fastest" — Similar save speed to an uncompressed file, smaller file size

  • "balanced" — Balance between file size and save speed

  • "compact" — Smallest file size, slowest save speed

  • "none" — Largest file size, fastest save speed

Example: export(mySigObj,To="file",Filename="myFile.parquet",ParquetCompression="balanced")

Since R2026a

Row grouping policy in Parquet file, specified as one of these options:

  • "height" — Define the row group by specifying the number of rows per group.

  • "sizeinmb" — Define the row group by specifying the size of the row group in megabytes.

Example: export(mySigObj,To="file",Filename="myFile.parquet",ParquetRowGroupPolicy="sizeinmb")

Since R2026a

Number of rows in row group, specified as "auto" or an integer between 1 and 67,108,864. By default, the value is "auto", which creates the largest possible row group without exceeding 512 MB.

To specify the row group height, ParquetRowGroupPolicy must be "height".

Example: export(mySigObj,To="file",Filename="myFile.parquet",ParquetRowGroupPolicy="height",ParquetRowGroupHeight=500)

Since R2026a

Row group size in megabytes, specified as a positive integer less than or equal to 1024. By default the row group size is 512 MB.

To specify the row group size, ParquetRowGroupPolicy must be "sizeinmb".

Example: export(mySigObj,To="file",Filename="myFile.parquet",ParquetRowGroupPolicy="sizeinmb",ParquetRowGroupSize=256)

Output Arguments

collapse all

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

When you export a single Simulink.sdi.Signal object, the output is a timeseries object.

When you export an array of Simulink.sdi.Signal objects or a Simulink.sdi.Run object, the output is a Simulink.SimulationData.Dataset object.

Do not use an output argument when you export data to a file.

Alternatives

To export data from multiple runs:

Version History

Introduced in R2017b

expand all