Main Content

Simulink.sdi.getCurrentSimulationRun

R2026b

Access data for in-progress or most recently completed simulation

Description

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.

example

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 a Run object to access the Simulink.sdi.Signal objects that correspond to individual signals in the run.

Access the in-progress or most recently completed simulation of the model named MyModel.

myRunObj = Simulink.sdi.getCurrentSimulationRun("MyModel");
myRunObj.Name
ans =

    'Run 5: MyModel'

If you have simulated multiple models in the current Simulation Data Inspector session, Simulink.sdi.getCurrentSimulationRun can return the Run object for the most recent simulation of any of those models. For example, suppose you also simulated the model MyOtherModel during this session. Use Simulink.sdi.getCurrentSimulationRun to get the Run object for latest simulation of MyOtherModel.

myOtherRunObj = Simulink.sdi.getCurrentSimulationRun("MyOtherModel");
myOtherRunObj.Name
ans =

    'Run 2: MyOtherModel'

When the model you specify is the most recently simulated model, you can also use Simulink.sdi.Run.getLatest. To get a Run object using the run ID, use Simulink.sdi.getRun.

Input Arguments

collapse all

Model name of the simulation data you want to access, specified as a string or character vector.

Example: "vdp"

Data Types: char | string

Output Arguments

collapse all

Run object for the in-progress or most recently completed simulation, returned as a Simulink.sdi.Run object.

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.

Version History

Introduced in R2020a