Main Content

Simulink.sdi.Run.getLatest

Get the most recently created Simulation Data Inspector run

Since R2020a

Description

example

runObj = Simulink.sdi.Run.getLatest returns the most recently created run in the Simulation Data Inspector repository. A run is created when you simulate a model that logs data or when you import data into the Simulation Data Inspector.

Examples

collapse all

Many tasks performed using the Simulation Data Inspector programmatic interface start by accessing the Simulink.sdi.Run object that corresponds to the logged or imported data you want to analyze. For example, you can use the Run object to access the Simulink.sdi.Signal objects that correspond to individual signals in the run.

This example shows how to access Run objects by using the Simulink.sdi.Run.getLatest function, the Simulink.sdi.getCurrentSimulationRun function, or the Simulink.sdi.getRun function.

Create a Run

The model sldemo_fuelsys is already configured for logging. When you simulate the model, the Simulation Data Inspector automatically creates a run and assigns it a run ID.

load_system('sldemo_fuelsys')
sim('sldemo_fuelsys')

Get Run Object Using Simulink.sdi.Run.getLatest

In this example, the run created when you simulated the model is the most recently created run in the Simulation Data Inspector. When you want to access the most recently created run, use the Simulink.sdi.Run.getLatest function.

fuelsysRun = Simulink.sdi.Run.getLatest;

Get Run Object Using Simulink.sdi.getCurrentSimulationRun

The run you want to access may not be the most recently created run in the Simulation Data Inspector. If the run corresponds to the most recent simulation of a model, you can use the Simulink.sdi.getCurrentSimulationRun function to access the Run object. You can also use the Simulink.sdi.getCurrentSimulationRun function to access data for an in-progress simulation when the simulation streams data to the Simulation Data Inspector. This function can be useful when you are working with multiple models.

In this example, the run created when you simulated the model is the current simulation run for the sldemo_fuelsys model.

fuelsysRun = Simulink.sdi.getCurrentSimulationRun('sldemo_fuelsys');

Get Run Object from a Run ID

When your task also requires the run ID, you can use the Simulink.sdi.getRun function to get the corresponding Simulink.sdi.Run object that contains the run data and metadata.

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

Output Arguments

collapse all

Simulink.sdi.Run object for the most recently created run in the Simulation Data Inspector.

Version History

Introduced in R2020a