Main Content

Simulink.sdi.DiffRunResult.getLatest

Access results from most recent comparison

Since R2020a

Description

diffRes = Simulink.sdi.DiffRunResult.getLatest returns the Simulink.sdi.DiffRunResult object diffRes for the most recent comparison performed using the Simulation Data Inspector UI or programmatic interface.

Tip

When you compare data using the Simulation Data Inspector UI, results are not returned in the workspace. You can use the Simulink.sdi.DiffRunResult.getLatest function to access results for comparisons performed using the Simulation Data Inspector UI. When you compare data using the Simulink.sdi.compareRuns or Simulink.sdi.compareSignals functions, the function returns the data in a Simulink.sdi.DiffRunResult object or a Simulink.sdi.DiffSignalResult object.

example

Examples

collapse all

Use the Simulink.sdi.DiffRunResult.getLatest function to access the results of the most recent comparison to save or process further. For more information about how to compare data using the Simulation Data Inspector UI, see Compare Simulation Data.

compResults = Simulink.sdi.DiffRunResult.getLatest;

You can use the Simulink.sdi.getCurrentComparison function or the Simulink.sdi.DiffRunResult.getResult function to retrieve the results for the most recent comparison if you accidentally delete the returned results from the workspace using the clear function.

If you delete the contents of the Simulation Data Inspector using the Simulink.sdi.clear function, you cannot recover the results.

Compare Simulation Data

This example creates runs to compare by running two simulations of the vdp model with different values for Mu.

mdl = "vdp";
load_system(mdl)

set_param("vdp/Mu","Gain","1");
out1 = sim(mdl);

set_param("vdp/Mu","Gain","2");
out2 = sim(mdl);

Use the Simulink.sdi.getAllRunIDs function to access the run IDs for the runs created from the simulations. Then use the Simulink.sdi.compareRuns function to compare the data.

IDs = Simulink.sdi.getAllRunIDs;
runID1 = IDs(end-1);
runID2 = IDs(end);

diffRun = Simulink.sdi.compareRuns(runID1,runID2);

Suppose you clear the workspace and lose the diffRun variable with the comparison results.

clear diffRun

Retrieve Comparison Data in the Workspace

Use the Simulink.sdi.getCurrentComparison function to recover the comparison results.

diffRun = Simulink.sdi.getCurrentComparison
diffRun = 
  DiffRunResult with properties:

       MatlabVersion: '24.2.0.2712019 (R2024b)'
              RunID1: 4
              RunID2: 25
     BaselineRunName: 'Run 1: vdp'
    CompareToRunName: 'Run 2: vdp'
               Count: 2
         DateCreated: 05-Sep-2024 19:24:45
     GlobalTolerance: [1x1 struct]
             Summary: [1x1 struct]
             Options: {'Units'  'MustMatch'}
              Status: Completed
          StopReason: []

You could also use the Simulink.sdi.DiffRunResult.getLatest function to recover the results.

clear diffRun

diffRun = Simulink.sdi.DiffRunResult.getLatest
diffRun = 
  DiffRunResult with properties:

       MatlabVersion: '24.2.0.2712019 (R2024b)'
              RunID1: 4
              RunID2: 25
     BaselineRunName: 'Run 1: vdp'
    CompareToRunName: 'Run 2: vdp'
               Count: 2
         DateCreated: 05-Sep-2024 19:24:45
     GlobalTolerance: [1x1 struct]
             Summary: [1x1 struct]
             Options: {'Units'  'MustMatch'}
              Status: Completed
          StopReason: []

Output Arguments

collapse all

Results of the most recent comparison, returned as a Simulink.sdi.DiffRunResult object.

Version History

Introduced in R2020a