Simulink.sdi.exportRun
Export Simulation Data Inspector run data to the workspace or a file
Description
creates a dataset
= Simulink.sdi.exportRun(runID
)Simulink.SimulationData.Dataset
object in the base workspace with the data from the Simulation Data Inspector run
identified by runID
.
In R2023a: To include data from multiple runs in the
Dataset
object, you can specify the runID
input as a vector of run IDs.
Simulink.sdi.exportRun(
exports the data in the run corresponding to runID
,Name,Value
)runID
to the base
workspace or a file according to the options specified by one or more name-value
pair arguments. You can export data for one or more runs to a MAT, MLDATX, or
Microsoft®
Excel® file. To export data for multiple runs to
the workspace (since R2023a) or a file, you can specify the runID
input as a vector of run IDs.
Examples
Export Run Data
You can export data from a run in the Simulation Data Inspector to a Simulink.SimulationData.Dataset
object in the base workspace that 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 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 to export run data to the workspace or a file when your workflow does not include creating a run object.
To create a run of simulation data, open the vdp
model, mark signals for logging, and run a simulation.
mdl = "vdp"; load_system(mdl); SignalHandles = get_param(mdl,"Lines"); Simulink.sdi.markSignalForStreaming(SignalHandles(5).Handle,"on") Simulink.sdi.markSignalForStreaming(SignalHandles(6).Handle,"on") out = sim(mdl);
Use the Simulink.sdi.getAllRunIDs
function to access the most recently created run.
runIDs = Simulink.sdi.getAllRunIDs; runID = runIDs(end);
Use the Simulink.sdi.exportRun
function to export the run data to a Dataset
object in the workspace.
simDataset = Simulink.sdi.exportRun(runID);
Export Run Using the export
Function
When your task involves creating a Run
object, you can use the export
function to create a Simulink.SimulationData.Dataset
object in the base workspace to further process the run data. For example, suppose you need to access Run
objects for simulation runs with signal data you want to compare using the Simulink.sdi.compareSignals
function.
Load a model and mark signals for logging. Then simulate the model to create run data.
load_system(mdl) SignalHandles = get_param(mdl,"Lines"); Simulink.sdi.markSignalForStreaming(SignalHandles(5).Handle,"on") Simulink.sdi.markSignalForStreaming(SignalHandles(6).Handle,"on") sim(mdl);
Use the Simulink.sdi.getAllRunIDs
function to access the run ID for the most recently created run. Then, use the Simulink.sdi.getRun
function to access the Run
object corresponding to the run.
runIDs = Simulink.sdi.getAllRunIDs; runID = runIDs(end); vdpRun = Simulink.sdi.getRun(runID);
Use the export
function to export the run data to a Dataset
object in the workspace.
simDataset = export(vdpRun);
Input Arguments
runID
— Run identifier
scalar | vector
Run identifier for the run you want to export to the workspace or a file.
You can export more than one run to the
workspace (since R2023a) or a file by specifying the runID
input as a vector of Simulation Data Inspector run IDs.
The Simulation Data Inspector assigns a unique run ID to each run. You can
get the run ID for one or more runs using Simulink.sdi.getAllRunIDs
and Simulink.sdi.getRunIDByIndex
.
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'
to
— Where to export data
'variable'
(default) | '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
, .mldatx
, or
.xlsx
extension.
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.
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 pairs.
Example: 'to','file'
filename
— Name of file to contain exported data
string | character array
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
, .mldatx
, or
.xlsx
extension in the file name to specify whether to
export the data to a MAT-file, MLDATX file, or a Microsoft
Excel file. When you do not specify an extension with a 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"
overwrite
— Data to overwrite in existing Microsoft Excel file
'file'
(default) | 'sheetsonly'
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 or MLDATX file, the exported data overwrites the entire file.
Example: 'overwrite','sheetsonly'
metadata
— Metadata to include in exported Microsoft Excel file
[]
(default) | string array
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 typeunits
— Signal unitsblockPath
— Path to the source block for logged signalsinterp
— Signal interpolation methodportIndex
— 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 in the string array does not affect the format in the exported file, which always matches the description in Microsoft Excel Import, Export, and Logging Format.
Example: 'metadata',["units","dataType"]
sharetimecolumn
— Whether signals share time columns in exported Microsoft Excel file
'on'
(default) | 'off'
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
dataset
— Dataset containing run data
Simulink.SimulationData.Dataset
Simulink.SimulationData.Dataset
object containing the data
from the run identified by runID
.
Version History
Introduced in R2017aR2023a: Output multiple runs to the workspace
To create a Dataset
object in the base workspace that contains
data from multiple runs in the Simulation Data Inspector, you can specify the
runID
input as a vector of Simulation Data Inspector run IDs.
Previously, you could only export multiple runs to a file.
Commande MATLAB
Vous avez cliqué sur un lien qui correspond à cette commande MATLAB :
Pour exécuter la commande, saisissez-la dans la fenêtre de commande de MATLAB. Les navigateurs web ne supportent pas les commandes MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)