주요 콘텐츠

Simulink.sdi.addToRun

R2026b

Import data into existing run in Simulation Data Inspector using run ID

Description

Import Data from Workspace

sigIDs = Simulink.sdi.addToRun(runID,"vars",var1,var2,...,varn) imports data from one or more variables into the Simulation Data Inspector run specified by runID.

To import data into a new run, use Simulink.sdi.Run.create or Simulink.sdi.createRun.

example

sigIDs = Simulink.sdi.addToRun(runID,"namevalue",sourceNames,sigValues) specifies values to use for the RootSource, TimeSource, and DataSource metadata properties of signals imported into the Simulation Data Inspector run.

example

Import Data from File

sigIDs = Simulink.sdi.addToRun(runID,"file",filename) imports data from a file into the Simulation Data Inspector run specified by runID. You can use a built-in file reader to import data from a MAT file, CSV file, Microsoft® Excel® file, Parquet file (since R2026b), or MDF file.

When you need to import data from a file that the built-in readers do not support, you can write your own reader using the io.reader class.

example

sigIDs = Simulink.sdi.addToRun(runID,"file",filename,Name=Value) specifies options when importing data from a file using one or more name-value arguments. For example, sheets=["sheet1" "sheet2"] specifies the sheets from which to import data when importing data from an Excel file.

Examples

collapse all

You can add data from the most recent simulation to a previous run.

Get the run ID for the run you want to add data to. For example, get the run ID for the first run logged during this Simulation Data Inspector session.

runIDs = Simulink.sdi.getAllRunIDs;
firstRunID = runIDs(1);

Add data from the most recent run to the first run. For example, add all signals logged using signal logging.

sigIDs = Simulink.sdi.addToRun(firstRunID,"vars",out.logsout);

The first run in the Simulation Data Inspector now contains all the data from that run plus the signals from the latest simulation.

To add data to a run and specify the RootSource, TimeSource, and DataSource properties of the added signals, use the "namevalue" argument. For example, the variable cos_ts contains timeseries data for a cosine wave. Add this signal to the run identified by myRunID and specify the source metadata as 'mySig'.

sigID = Simulink.sdi.addToRun(myRunID,"namevalue",{'mySig'},{cos_ts});

Verify the source metadata of the signal.

mySignal = Simulink.sdi.getSignal(sigID);
mySigRootSource = mySignal.RootSource
mySigRootSource = 'mySig'
mySigTimeSource = mySignal.TimeSource
mySigTimeSource = 'mySig.Time'
mySigDataSource = mySignal.DataSource
mySigDataSource = 'mySig.Data'

To add data from a file to an existing run, use the "file" argument. For example, add the data from the MAT file named MyData to the most recent run.

runIDs = Simulink.sdi.getAllRunIDs;
latestRunID = runIDs(end);
Simulink.sdi.addToRun(latestRunID,"file","MyData.mat")

Input Arguments

collapse all

Run ID for run to which you want to add imported data, specified as a scalar.

The Simulation Data Inspector assigns a unique ID to each run when the run is created. You can access run IDs for runs in the Simulation Data Inspector using the Simulink.sdi.getAllRunIDs and Simulink.sdi.getRunIDByIndex functions.

Data to import, specified as one or more variables. The Simulation Data Inspector supports time-based data in which sample values correspond to sample times. The Simulation Data Inspector supports all loading and logging data formats, including timeseries and Simulink.SimulationData.Dataset.

Example: myData

Source names for imported data, specified as a cell array of character vectors. The source name is used to set the RootSource, TimeSource, and DataSource properties of the Simulink.sdi.Signal objects created from the data specified by the sigValues input.

Provide a sourceNames input when you specify "namevalue" for the second argument.

Example: {'sig1','sig2'}

Data to import, specified as a cell array of variables.

Provide a sigValues input when you specify "namevalue" for the second argument.

Example: {var1,var2}

Name of file with data to import, specified as a character vector. Provide a filename input when you specify "file" for the second argument.

You can create a run from these types of files using file readers built into the Simulation Data Inspector:

When you need to import data from a file that the built-in readers do not support, you can write your own reader using the io.reader class. You can also write a custom reader to use instead of the built-in reader for any file extension. For an example, see Import Data Using Custom File Reader.

Example: 'simulation.mat'

Name-Value Arguments

collapse 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: Sheets=["sheet1" "sheet2"]

File reader to use to import data, specified as a string or character vector.

The Simulation Data Inspector prioritizes using a registered custom reader if one is available for the file. If you do not specify a reader, the Simulation Data Inspector uses the first custom reader registered for the file. If no custom readers are registered, the Simulation Data Inspector imports the data using the built-in reader.

Specify the reader input when:

  • You want to use the built-in reader to import data for a file that is also supported by a custom reader.

  • Multiple registered custom readers support the file.

To determine which readers are available to import your file, use the io.reader.getSupportedReadersForFile function.

Example: Reader="MyExcelReader"

Example: Reader="built-in"

Sheets in Excel file from which to import data, specified as a string array or a cell array of character vectors. By default, the Simulation Data Inspector imports data from all sheets. Specify Sheets to limit the import to specific sheets.

If the data in the file does not include simulation numbers and source information, the Simulation Data Inspector imports the data on each sheet into a separate run. For more information about formatting data to import from an Excel file, see Microsoft Excel Import, Export, and Logging Format.

Example: Sheets=["sheet1" "sheet2"]

Model with definitions of user-defined data types, specified as a string or character vector.

If you load data from a CSV or Excel file that defines signal data types using user-defined data types, such as enumerations, buses, or aliases, the Simulation Data Inspector requires access to the type definition to import the data. You can provide access to the type definitions by:

  • Loading the associated object into the MATLAB® workspace.

  • Specifying the Model name-value argument to use type definitions saved in the model workspace or a data dictionary.

For information about formatting data to import, see CSV File Format for Simulation Data or Microsoft Excel Import, Export, and Logging Format.

Example: Model="myModel.slx"

Names of signals to import from a Parquet file, specified as a string, string array, character vector, or cell array of character vectors. By default, the Simulation Data Inspector imports all signals from the file. To selectively import specific signals, use the SignalNames or ColumnIndices name-value argument.

Signal names must match exactly and are case-sensitive. To identify the signal names available in a Parquet file, use Simulink.sdi.Parquet.getSignalMetadata.

To import all elements of a bus, specify the bus parent name. For example, to import all elements from a bus named VehicleBus, specify SignalNames="VehicleBus". To import only some elements of a bus, use dot notation. For example, SignalNames="VehicleBus.Velocity" imports only the Velocity element.

Example: SignalNames=["Sine" "Cosine"]

Column indices of signals to import from a Parquet file, specified as a positive integer or vector of positive integers. By default, the Simulation Data Inspector imports all signals from the file. To selectively import specific signals, use the SignalNames or ColumnIndices name-value argument.

Column indices refer to data columns only. The Simulation Data Inspector automatically imports time columns with the corresponding data columns. To identify the column indices for signals in a Parquet file, use Simulink.sdi.Parquet.getSignalMetadata.

Example: ColumnIndices=[1 3 5]

Output Arguments

collapse all

Signal IDs for signals created from imported data, returned as a scalar or a vector.

Version History

Introduced in R2011b

expand all