Main Content


Save comparison results to an MLDATX file



saveResult(DiffRes,fileName) saves the comparison results in the Simulink.sdi.DiffRunResult object, 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 Simulink.sdi.load or open functions.

saveResult(DiffRes,fileName,saveRuns) saves the comparison results with or without the original run data, depending on the specified value for saveRuns.


collapse all

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.


set_param('ex_sldemo_absbrake/Desired relative slip','Value','0.24')
out_1 = sim('ex_sldemo_absbrake');

Use the 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 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.

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 Simulink.sdi.DiffSignalResult object.

signalResult_Ww = getResultByIndex(runResult,1)
signalResult_Ww = 
  DiffSignalResult with properties:

             Name: 'yout.Ww'
           Status: OutOfTolerance
          AlignBy: 'Path'
        SignalID1: 144229
        SignalID2: 144275
    MaxDifference: 12.4878
            Sync1: [1x1 timeseries]
            Sync2: [1x1 timeseries]
             Diff: [1x1 timeseries]

ans = 

The 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.


The MLDATX file desiredSlipResults is created in the working directory. Use the Simulink.sdi.load function or the open function to view the results in the MLDATX file.

Input Arguments

collapse all

Run comparison results that contain the data you want to save, specified as a Simulink.sdi.DiffRunResult object.

Name of the MLDATX file where you want to save the results, specified as a string or character array.

Example: 'ComparisonResults'

Whether to save the original run data for the compared runs, specified as a logical 1 (true) or 0 (false). By default, the saveResult function saves the original run data along with the comparison results.

Introduced in R2020a