%% Compare Runs with Global Tolerance
% You can specify global tolerance values to use when comparing two simulation runs. Global tolerance values are applied to all signals within the run. This example shows how to specify global tolerance values for a run comparison and how to analyze and save the comparison results.
% First, load the session file that contains the data to compare. The session file contains data for four simulations of an aircraft longitudinal controller. This example compares data from two runs that use different input filter time constants.

Simulink.sdi.load('AircraftExample.mldatx');

%
% To access the run data to compare, use the Simulink.sdi.getAllRunIDs function to get the run IDs that correspond to the last two simulation runs.

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

%
% Use the Simulink.sdi.compareRuns function to compare the runs. Specify a global relative tolerance value of 0.2 and a global time tolerance value of 0.5.

runResult = Simulink.sdi.compareRuns(runID1,runID2,'reltol',0.2,'timetol',0.5);

%
% Check the Summary property of the returned Simulink.sdi.DiffRunResult object to see whether signals were within the tolerance values or out of tolerance.

runResult.Summary

% All three signal comparison results fell within the specified global tolerance.
%
% You can save the comparison results to an MLDATX file using the saveResult function.

saveResult(runResult,'InputFilterComparison');

% Copyright 2019 The MathWorks, Inc.
%