Main Content

Simulink.sdi.getCurrentSimulationRun

Access data for in-progress or most recently completed simulation

Description

example

runObj = Simulink.sdi.getCurrentSimulationRun(mdl) returns the Simulink.sdi.Run object that corresponds to the in-progress or most recently completed simulation of the model specified by mdl. If you delete the Run object that corresponds to the most recently completed simulation, the Simulink.sdi.getCurrentSimulationRun function returns empty.

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);

Input Arguments

collapse all

Name of the model that created the simulation data you want to access, specified as a string or character array.

Example: 'vdp'

Data Types: char | string

Output Arguments

collapse all

Simulink.sdi.Run object that corresponds to the in-progress or most recently completed simulation.

Tips

  • You can use the Simulink.sdi.getCurrentSimulationRun function to access logged data in a StopFcn model callback function. Workspace variable data is not available when the StopFcn callback executes, but the Run object is available because data streams to the Simulation Data Inspector.

  • You can use the Simulink.sdi.getCurrentSimulationRun function to analyze run data on parallel workers to determine whether to send the run data to the Simulation Data Inspector.

Introduced in R2020a