Main Content

saveResult

Save comparison results to an MLDATX file

Since R2020a

Description

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.

example

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

Examples

collapse all

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.

Load the Simulation Data Inspector session file that contains the data to compare. The session file contains data for four simulations of an aircraft longitudinal flight 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 are within the tolerance values or out of tolerance.

runResult.Summary
ans = struct with fields:
       OutOfTolerance: 0
      WithinTolerance: 3
            Unaligned: 0
        UnitsMismatch: 0
                Empty: 0
             Canceled: 0
          EmptySynced: 0
     DataTypeMismatch: 0
         TimeMismatch: 0
    StartStopMismatch: 0
          Unsupported: 0

All three signal comparison results fall within the specified global tolerance.

You can save the comparison results to an MLDATX file using the saveResult function.

saveResult(runResult,"InputFilterComparison");

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.

Version History

Introduced in R2020a