Save comparison results to an MLDATX file
saves the comparison results in the
DiffRes, and original run data to the MLDATX file,
fileName. You can load the MLDATX file containing the runs and
comparison results into the Simulation Data Inspector using the
This example shows how to compare runs of simulation data and then analyze and save the results using the Simulation Data Inspector programmatic interface.
Create Simulation Data
First, create simulation data by simulating a model that logs data. This example uses the
ex_sldemo_absbrake model and analyzes the effect of changing the
Desired relative slip value.
Load the model. Use the
set_param function to specify an initial value for the relative slip and simulate the model.
load_system('ex_sldemo_absbrake') set_param('ex_sldemo_absbrake/Desired relative slip','Value','0.24') out_1 = sim('ex_sldemo_absbrake');
set_param function to specify a different value for the relative slip and simulate the model again.
set_param('ex_sldemo_absbrake/Desired relative slip','Value','0.25') out_2 = sim('ex_sldemo_absbrake');
Compare Runs Using Global Tolerance Values
First, 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);
Now, 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
runResult = Simulink.sdi.compareRuns(runID1,runID2,'reltol',0.2,'timetol',0.5);
Summary property of the returned
ans = struct with fields: OutOfTolerance: 2 WithinTolerance: 2 Unaligned: 0 UnitsMismatch: 0 Empty: 0 Canceled: 0 EmptySynced: 0 DataTypeMismatch: 0 TimeMismatch: 0 StartStopMismatch: 0 Unsupported: 0
Two signal comparisons within the run were within tolerance, and two were out of tolerance.
Plot Comparison Results
You can use plots to analyze the comparison results. Access the signal result for the
Ww signal from the
DiffRunResult object that contains the comparison results using the
getResultByIndex function. Check the
Status property of the
signalResult_Ww = getResultByIndex(runResult,1)
signalResult_Ww = DiffSignalResult with properties: Status: OutOfTolerance AlignBy: 'Path' SignalID1: 39404 SignalID2: 39450 MaxDifference: 12.4878 Sync1: [1x1 timeseries] Sync2: [1x1 timeseries] Diff: [1x1 timeseries]
ans = OutOfTolerance
Ww signal comparison results are out of tolerance. Plot the difference signal to analyze the result.
Save Comparison Results
You can save the comparison results to an MLDATX file to analyze later or to share with a colleague. Use the
saveResult function to save the run data and comparison results.
DiffRes— Run comparison results
Run comparison results that contain the data you want to save, specified as a
fileName— MLDATX file name
Name of the MLDATX file where you want to save the results, specified as a string or character array.
saveRuns— Whether to save original run data
Whether to save the original run data for the compared runs, specified as a logical
false). By default, the
saves the original run data along with the comparison results.