Main Content

Simulink.sdi.DiffSignalResult

Access signal comparison results

Description

When you compare runs or signals using the Simulation Data Inspector, the results are returned as either a Simulink.sdi.DiffSignalResult object or a Simulink.sdi.DiffRunResult object that contains one or more Simulink.sdi.DiffSignalResult objects. The DiffSignalResult object contains the data and metadata for signal comparison results, such as the difference signal, tolerance data, and the synchronized signal data.

Creation

When you use the Simulation Data Inspector to compare runs or signals, you can access signal comparison results in a Simulink.sdi.DiffSignalResult object two ways:

Properties

expand all

This property is read-only.

Baseline signal name, returned as a character vector. When comparison results are complex, the name of the DiffSignalResult object that contains the real data is appended with (real), and the name of the DiffSignalResult object that contains the imaginary data is appended with (imag).

This property is read-only.

Status of the signal comparison corresponding to the DiffSignalResult object, returned as one of the following options. The status can indicate where a given signal comparison is in the comparison process during a long comparison, or it can indicate information about the result of the signal comparison.

  • WithinTolerance — Signal comparison completed, and all data points compared fell within the specified tolerance.

  • OutOfTolerance — Signal comparison completed, and some data points compared fell outside of the specified tolerance.

  • Unaligned — Signal from the baseline run did not align with a signal in the run to compare.

  • Empty — Aligned signal in the baseline run or run to compare contains no data.

  • EmptySynced — Synchronized signal in the baseline run or run to compare contains no data. An empty synchronized signal can mean that the signals do not overlap or, if you specified the intersection synchronization method, that they included none of the same time points.

  • Canceled — Signal result not computed because the user canceled the comparison or the algorithm ended the comparison before computing this signal result.

  • Pending — Comparison is in progress and the signal result computation has not started.

  • Processing — Signal result computation in progress.

  • UnitsMismatch — The signal units in the baseline run and run to compare do not match.

  • DataTypeMismatch — The signal data types in the baseline run and run to compare do not match. Only results of comparisons configured to check signal data types can have this status.

  • TimeMismatch — The signal time vectors in the baseline run and run to compare do not match. Only results of comparisons configured to check signal time vectors can have this status.

  • StartStopMismatch — The signal start and stop times in the baseline run and run to compare do not match. Only results of comparisons configured to check signal start and stop times can have this status.

  • Unsupported — The Simulation Data Inspector comparison algorithm does not support this type of signal. For example, signals with data types that lose precision when converted to double are not supported.

For more information about alignment, tolerances, and synchronization, see How the Simulation Data Inspector Compares Data. For more information about configuring comparisons to check for additional metadata, see Simulink.sdi.compareRuns.

This property is read-only.

Property by which signals aligned in a run comparison, returned as a character vector. When the DiffSignalResult object was created from a signal comparison, the AlignBy property is empty. For more information about how run comparisons align signals, see How the Simulation Data Inspector Compares Data.

This property is read-only.

Unique signal identifier for the baseline signal in the comparison, returned as an integer.

This property is read-only.

Unique signal identifier for the signal to compare against the baseline signal, returned as an integer.

This property is read-only.

Maximum difference between the two comparison signals, returned as a double.

This property is read-only.

Synchronized baseline signal, returned as a timeseries object. For more information about synchronization, see How the Simulation Data Inspector Compares Data.

This property is read-only.

Synchronized signal to compare, returned as a timeseries object. For more information about synchronization, see How the Simulation Data Inspector Compares Data.

This property is read-only.

Difference signal resulting from the comparison, returned as a timeseries object.

Examples

collapse all

This example uses the slexAircraftExample model to demonstrate how to compare the input and output signals of the control system.

Configure and Simulate the Model

The slexAircraftExample model does not log data. Load the model and mark the input and output signals for logging.

load_system('slexAircraftExample')
Simulink.sdi.markSignalForStreaming('slexAircraftExample/Pilot',1,'on')
Simulink.sdi.markSignalForStreaming('slexAircraftExample/Aircraft Dynamics Model',4,'on')

Simulate the model. The data for the logged signals logs to the Simulation Data Inspector and to the workspace.

out = sim('slexAircraftExample');

Access Simulation Data

Use the Simulation Data Inspector programmatic interface to access the data. The Simulink.sdi.Run.getLatest function returns the most recently created run in the Simulation Data Inspector repository. Use the getSignalIDByIndex function to access the signal IDs for the logged signals.

aircraftRun = Simulink.sdi.Run.getLatest;

signalID1 = getSignalIDByIndex(aircraftRun,1);
signalID2 = getSignalIDByIndex(aircraftRun,2);

Specify Tolerance Values

You can specify tolerance values to use in the comparison as a property in the logged Simulink.sdi.Signal object. Use the Simulink.sdi.getSignal function to access the Signal object using the signal ID.

signal1 = Simulink.sdi.getSignal(signalID1);
signal1.AbsTol = 0.1;

Compare Signals

Use the Simulink.sdi.compareSignals function to compare the input and output signals. This example uses the isValidSignalID function to verify that both signal IDs are still valid before calling the Simulink.sdi.compareSignals function. A signal ID becomes invalid when the signal is deleted from the Simulation Data Inspector. After the comparison, check the status in the Simulink.sdi.DiffSignalResult object.

if (isValidSignalID(aircraftRun,signalID1) && isValidSignalID(aircraftRun,signalID2))
    sigDiff = Simulink.sdi.compareSignals(signalID1,signalID2);

    match = sigDiff.Status
end
match = 
OutOfTolerance

The comparison result is out of tolerance. You can use the Simulink.sdi.view function to inspect and analyze the comparison results.

Alternatives

You can view and inspect comparison results using the Simulation Data Inspector UI. For more information, see Compare Simulation Data.

Introduced in R2012b