This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Simulink.sdi.exportRun

Export run data to a Simulink.SimulationData.Dataset object

Syntax

dataset = Simulink.sdi.exportRun(runID)
Simulink.sdi.exportRun(runID,Name,Value)

Description

example

dataset = Simulink.sdi.exportRun(runID) creates a Simulink.SimulationData.Dataset object in the base workspace with the data in the Simulation Data Inspector run identified by runID.

example

Simulink.sdi.exportRun(runID,Name,Value) exports the data in the run corresponding to runID 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 export data from a run in the Simulation Data Inspector to a Simulink.SimulationData.Dataset object in the base workspace you can use to further process your data. The method you choose to export your run depends on the processing you do in your script. If you have a run object for the run, you can use the export method to create a Simulink.SimulationData.Dataset object with the run's data in the base workspace. If you do not have a run object, use the Simulink.sdi.exportRun function to export the run to the workspace.

Export Run Using Simulink.sdi.exportRun

Use the Simulink.sdi.export function when your workflow does not include creating a run object.

% Load vdp model
load_system('vdp')

% Get handles for signal lines in model
SignalHandles = get_param('vdp', 'Lines');

% Mark signals for streaming
Simulink.sdi.markSignalForStreaming(SignalHandles(5).Handle, 'on')
Simulink.sdi.markSignalForStreaming(SignalHandles(6).Handle, 'on')

% Simulate vdp model
sim('vdp')
ans = 
  Simulink.SimulationOutput:

                logsout: [1x1 Simulink.SimulationData.Dataset] 

     SimulationMetadata: [1x1 Simulink.SimulationMetadata] 
           ErrorMessage: [0x0 char] 

% Get run ID for simulation run
runIDs = Simulink.sdi.getAllRunIDs;
runID = runIDs(end);

% Export run
simDataset = Simulink.sdi.exportRun(runID);

Export Run Using export Method

When you already have a Simulink.sdi.Run object for your run, you can use the export method to create a Simulink.SimulationData.Dataset object in the base workspace for further processing of the data.

% Load vdp model
load_system('vdp')

% Get handles for signal lines in model
SignalHandles = get_param('vdp', 'Lines');

% Mark signals for streaming
Simulink.sdi.markSignalForStreaming(SignalHandles(5).Handle, 'on')
Simulink.sdi.markSignalForStreaming(SignalHandles(6).Handle, 'on')

% Simulate model vdp and get run object
sim('vdp')
ans = 
  Simulink.SimulationOutput:

                logsout: [1x1 Simulink.SimulationData.Dataset] 

     SimulationMetadata: [1x1 Simulink.SimulationMetadata] 
           ErrorMessage: [0x0 char] 

% Get run object for simulation run
runIDs = Simulink.sdi.getAllRunIDs;
runID = runIDs(end);
vdpRun = Simulink.sdi.getRun(runID);

% Get signal ids for signals
sigID1 = vdpRun.getSignalIDByIndex(1);
sigID2 = vdpRun.getSignalIDByIndex(2);

% Compare signals
diffResult = Simulink.sdi.compareSignals(sigID1,sigID2);
diffResult.match
ans = logical
   0

% Export run
simDataset = vdpRun.export;

Input Arguments

collapse all

Run identifier for the run you want to export to a Simulink.SimulationData.Dataset. The Simulation Data Inspector assigns a unique run ID when it creates a run. You can get the run ID for your run using Simulink.sdi.getAllRunIDs and Simulink.sdi.getRunIDByIndex.

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'

Specify whether to export data to a variable in the base workspace or to a 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, the data is saved in the MAT-file as a timeseries object. When you export a run to a MAT-file, the data is saved in a Simulink.SimulationData.Dataset object.

Data exported to a Microsoft® Excel® file is saved with the format described in Simulation Data Inspector Import and Export File 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 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"

Specify data to overwrite in existing file. When you export data to a Microsoft Excel file that already exists, you can control whether the export overwrites the entire file or only the affected sheets in the file.

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

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

Example: 'overwrite','sheetsonly'

Metadata to include in the exported Microsoft Excel file, specified in 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 Simulation Data Inspector Import and Export File Format.

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

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

Simulink.SimulationData.Dataset object containing the data from the run identified by runID.

Introduced in R2017a