Simulink.sdi.getCurrentComparison

Access results from most recent comparison

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: '9.8.0.1323502 (R2020a)'
             RunID1: 5
             RunID2: 26
              Count: 2
        DateCreated: 29-Feb-2020 02:23:06
    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: '9.8.0.1323502 (R2020a)'
             RunID1: 5
             RunID2: 26
              Count: 2
        DateCreated: 29-Feb-2020 02:23:06
    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.

Introduced in R2020a