export

Export Simulink.sdi.Signal object to workspace or file

Description

example

ts = export(sig) exports the Simulink.sdi.Signal object sig to the timeseries object, ts, in the MATLAB® workspace.

ts = export(sig,startTime,endTime) exports the portion of the Simulink.sdi.Signal object defined by startTime and endTime to the timeseries object, ts, in the MATLAB workspace.

export(___,Name,Value) exports the Simulink.sdi.Signal object to the base workspace or a file according to the options specified by one or more name-value pair arguments.

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.

Start time for the signal portion to export, specified as an integer.

Example: 0

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

End time for the signal portion to export, specified as an integer.

Example: 10

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

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'to','file'

Where to export data, specified as the comma-separated pair consisting of 'to' and 'variable' or 'file'.

When you export data to a file, you must also specify a file name using the 'filename' name-value pair argument. You can specify a file name with a .mat or .xlsx extension.

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

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

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

Example: 'to','file'

Name of the file to contain the exported data, specified as the comma-separated pair consisting of 'filename' and a string or character array. Include a .mat or .xlsx extension in the file name to specify whether to export to a MAT-file or a Microsoft Excel file. When you do not specify an extension with the file name, the data exports to a MAT-file.

Use the 'filename' name-value pair argument when you specify the 'to' name-value pair argument with the value 'file'.

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

Example: 'filename',"mySpreadsheet.xlsx"

Data to overwrite in existing Microsoft Excel file, specified as the comma-separated pair consisting of 'overwrite' and 'file' or 'sheetsonly'.

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

  • 'sheetsonly' — Only overwrite sheets of the Microsoft Excel file with data that corresponds to the exported data.

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 the comma-separated pair consisting of 'metadata' and a string array. By default, the export operation does not include any metadata. You can export this metadata to the 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

You can specify the desired metadata in any order you choose in the string array. The order of the metadata does not affect the format in the exported file, which always matches the description in Microsoft Excel Import and Export Format.

Example: 'metadata',["units","dataType"]

Whether signals that have identical time data share time columns in the exported Microsoft Excel file, specified as the comma-separated pair consisting of 'sharetimecolumn' and 'on' or 'off'. By default, signals with the same 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.

Alternatives

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

Introduced in R2017b