Simulink.sdi.getRun

Get a Simulink.sdi.Run object to access data

Description

example

run = Simulink.sdi.getRun(runID) returns a Simulink.sdi.Run object that provides access to the data in the run corresponding to the runID. The Simulation Data Inspector assigns run IDs when it creates a run. You can get the run ID for your run using Simulink.sdi.getAllRunIDs or Simulink.sdi.getRunIDByIndex.

Examples

collapse all

Many workflows using the Simulation Data Inspector programmatic interface start with acquiring a Simulink.sdi.Run object for your simulation data.

% Load and simulate system
load_system('sldemo_fuelsys')
sim('sldemo_fuelsys')

% Get runID for most recent run
runIDs = Simulink.sdi.getAllRunIDs;
runID = runIDs(end);

% Get run object
run = Simulink.sdi.getRun(runID);

You can use the Simulink.sdi.Run object to access signal data, add data, and inspect run metadata.

This example demonstrates how to access the Simulink.sdi.Run object for a Simulation Data Inspector run created by logging signals. From the Simulink.sdi.Run object you can get Simulink.sdi.Signal objects that you can use to plot the data.

Create a Simulation Run and Access the Run Object

The sldemo_fuelsys model includes several signals that are marked for logging. To create a simulation run containing the logged data, simulate the model.

sim('ex_vdp');

The Simulation Data Inspector keeps track of runs by assigning each run created by simulation, importing data, or opening a session a unique numeric ID. To access the run object for the simulation just performed, use the Simulink.sdi.getAllRunIDs function and take the last run ID in the returned vector.

runIDs = Simulink.sdi.getAllRunIDs;
runID = runIDs(end);

Once you have the run ID for the run of interest, you can use the Simulink.sdi.getRun function to get the Simulink.sdi.Run object corresponding to the run. You can use the Run object to check metadata associated with the run, including the number of signals in the run.

vdpRun = Simulink.sdi.getRun(runID);

vdpRun.SignalCount
ans = int32
    2

Plot Data Using Signal Objects

Use the getSignalByIndex function to access signals of interest from the Run object, fuelRun.

signal1 = getSignalByIndex(vdpRun,1);
signal2 = getSignalByIndex(vdpRun,2);

Use the Simulink.sdi.setSubPlotLayout function to specify a 3-by-1 layout.

Simulink.sdi.setSubPlotLayout(2,1)

Before plotting the data, use the Simulink.sdi.clearAllSubPlots function to clear any data that is already plotted.

Simulink.sdi.clearAllSubPlots

Plot one signal on each subplot. To plot signals on the first subplot, you can set the checked property for the signal. To plot signals on subplots other than the first subplot, use the plotOnSubPlot function.

signal1.Checked = true;
plotOnSubPlot(signal2,2,1,true);

View the Plotted Data

To view the plots you just created, open the Simulation Data Inspector using the Simulink.sdi.view function.

Input Arguments

collapse all

Run ID for the run you want a Simulink.sdi.Run object for. The Simulation Data Inspector assigns run IDs when it creates runs. You can get the run ID for a run using Simulink.sdi.getAllRunIDs or Simulink.sdi.getRunIDByIndex.

Output Arguments

collapse all

Simulink.sdi.Run object for the run corresponding to the run ID.

Introduced in R2011b