Main Content


Get all Simulation Data Inspector run identifiers



runIDs = Simulink.sdi.getAllRunIDs returns a matrix of the run identifiers for all runs in the Simulation Data Inspector repository.


collapse all

Many tasks performed using the Simulation Data Inspector programmatic interface start with obtaining the run ID for a simulation run. This example illustrates several methods to get the run ID for a run. You can use the run ID to access the Simulink.sdi.Run object that contains the run data and metadata and perform run comparisons using the Simulink.sdi.compareRuns 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.


Get Run ID Using Simulink.sdi.getAllRunIDs

The Simulink.sdi.getAllRunIDs function returns an array of all run IDs for the runs in the Simulation Data Inspector repository, in order, with the most recently created run at the end.

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

Get Run ID Using Simulink.sdi.getRunIDByIndex

You can also use the Simulink.sdi.getRunCount and Simulink.sdi.getRunIDByIndex functions to get the run ID for a run. This method is useful if you also want to use count as a counting variable to index through the runs in the Simulation Data Inspector repository.

count = Simulink.sdi.getRunCount;
runID = Simulink.sdi.getRunIDByIndex(count);

Get Run ID from a Simulink.sdi.Run Object

You can also get the run ID from the Simulink.sdi.Run object that corresponds to the run. This example uses the Simulink.sdi.getCurrentSimulationRun function to get the Run object that corresponds to the most recent simulation of the sldemo_fuelsys model. You can also use the Simulink.sdi.Run.getLatest function to access the most recently created Run object.

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

Using the Simulation Data Inspector programmatic interface, you can specify signal tolerance values to use in comparisons. This example uses the slexAircraftExample model and the Simulation Data Inspector to evaluate the effect of changing the time constant for the low-pass filter following the control input.

Configure the Model

Load the model and mark signals of interest for logging. This example logs data for the q and alpha signals.


Simulink.sdi.markSignalForStreaming('slexAircraftExample/Aircraft Dynamics Model',3,'on')
Simulink.sdi.markSignalForStreaming('slexAircraftExample/Aircraft Dynamics Model',4,'on')

Run Simulations

Run simulations with different low-pass filter time constants to generate results to compare. The slexAircraftExample model stores variables associated with the model in the model workspace. To modify the time constant value, access the model workspace and use the assignin function.

out1 = sim('slexAircraftExample');

modelWorkspace = get_param('slexAircraftExample','modelworkspace');

out2 = sim('slexAircraftExample');

Access and Compare Simulation Results

Access the simulation results using the Simulation Data Inspector programmatic interface. Each simulation creates a run in the Simulation Data Inspector with a unique run ID. You use the run IDs to compare the simulation results.

runIDs = Simulink.sdi.getAllRunIDs;
runIDTs1 = runIDs(end-1);
runIDTs2 = runIDs(end);

Use the Simulink.sdi.compareRuns function to compare the data from the simulations. Then inspect the Status property of the signal result to see whether the signals fell within the default tolerance of 0.

diffRun1 = Simulink.sdi.compareRuns(runIDTs1,runIDTs2);

sig1Result1 = getResultByIndex(diffRun1,1);
sig2Result1 = getResultByIndex(diffRun1,2);

ans = 
ans = 

Compare Runs with Signal Tolerances

By default, signals use 0 for all tolerance values, so the comparison returns out-of-tolerance results when the signals are not identical. To further analyze the effect of the time constant change, specify tolerance values for the signals. You can specify tolerances for a programmatic comparison using the properties of the Simulink.sdi.Signal objects in the runs you compare. The comparison uses the tolerances specified for the baseline Signal object. This example specifies a combination of time and absolute tolerances.

To specify tolerances, first access the Simulink.sdi.Signal objects that correspond to each signal in the runs you want to compare.

run1 = Simulink.sdi.getRun(runIDTs1);
sigID1 = getSignalIDByIndex(run1,1);
sigID2 = getSignalIDByIndex(run1,2);

sig1 = Simulink.sdi.getSignal(sigID1);
sig2 = Simulink.sdi.getSignal(sigID2);

Check the Name property to identify each Signal object.

ans = 
'q, rad/sec'
ans = 
'alpha, rad'

Specify an absolute tolerance of 0.1 and a time tolerance of 0.6 for the q signal using the AbsTol and TimeTol properties of the q signal object in the baseline run.

sig1.AbsTol = 0.1;
sig1.TimeTol = 0.6;

Specify an absolute tolerance of 0.2 and a time tolerance of 0.8 for the alpha signal using the AbsTol and TimeTol properties of the alpha signal object in the baseline run.

sig2.AbsTol = 0.2;
sig2.TimeTol = 0.8;

Compare the runs again and access the results.

diffRun2 = Simulink.sdi.compareRuns(runIDTs1,runIDTs2);
sig1Result2 = getResultByIndex(diffRun2,1);
sig2Result2 = getResultByIndex(diffRun2,2);

Check the Status property of each signal to determine whether the comparison results fell within the specified tolerances.

ans = 
ans = 

Output Arguments

collapse all

Matrix of run IDs in the Simulation Data Inspector repository.

Introduced in R2017a