Main Content

Simulink.sdi.getCurrentComparison

Access results from most recent comparison

Since R2020a

Description

example

diffRes = Simulink.sdi.getCurrentComparison 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.getCurrentComparison 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.

Examples

collapse all

Use the Simulink.sdi.getCurrentComparison 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.getCurrentComparison;

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 model ex_vdp with different values for Mu.

load_system('ex_vdp')

set_param('ex_vdp/Mu','Gain','2');
out1 = sim('ex_vdp');

set_param('ex_vdp/Mu','Gain','5');
out2 = sim('ex_vdp');

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.1.0.2508561 (R2024a)'
              RunID1: 4
              RunID2: 25
     BaselineRunName: 'Run 1: ex_vdp'
    CompareToRunName: 'Run 2: ex_vdp'
               Count: 2
         DateCreated: 13-Feb-2024 01:11:20
     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.1.0.2508561 (R2024a)'
              RunID1: 4
              RunID2: 25
     BaselineRunName: 'Run 1: ex_vdp'
    CompareToRunName: 'Run 2: ex_vdp'
               Count: 2
         DateCreated: 13-Feb-2024 01:11:20
     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