Main Content


Compare data in two Simulink.sdi.Signal objects



diff = Simulink.sdi.compareSignals(sigID1,sigID2) compares the signals that correspond to the signal IDs sigID1 and sigID2 and returns the results in a Simulink.sdi.DiffSignalResult object. For more information on how the comparison results are computed, see How the Simulation Data Inspector Compares Data.


collapse all

You can use the Simulation Data Inspector programmatic interface to compare signals within a single run. This example compares the input and output signals of an aircraft longitudinal controller.

First, load the session that contains the data.


Use the Simulink.sdi.Run.getLatest function to access the latest run in the data.

aircraftRun = Simulink.sdi.Run.getLatest;

Then, you can use the Simulink.sdi.getSignalsByName function to access the Stick signal, which represents the input to the controller, and the alpha, rad signal that represents the output.

stick = getSignalsByName(aircraftRun,'Stick');
alpha = getSignalsByName(aircraftRun,'alpha, rad');

Before you compare the signals, you can specify a tolerance value to use for the comparison. Comparisons use tolerance values specified for the baseline signal in the comparison, so set an absolute tolerance value of 0.1 on the Stick signal.

stick.AbsTol = 0.1;

Now, compare the signals using the Simulink.sdi.compareSignals function. The Stick signal is the baseline, and the alpha, rad signal is the signal to compare against the baseline.

comparisonResults = Simulink.sdi.compareSignals(stick.ID,alpha.ID);
match = comparisonResults.Status
match = 
  ComparisonSignalStatus enumeration


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

This example shows how to compare signals from different simulation runs using the Simulation Data Inspector's Simulink.sdi.compareSignals function. When you only have one signal of interest to compare, using a signal comparison returns the Simulink.sdi.diffSignalResult object with the comparison data directly.

Generate Simulation Data

Use the slexAircraftExample model to generate simulation runs. Between the runs, change the time constant of the input filter.

% Load example model

% Mark the alpha, rad signal for streaming
Simulink.sdi.markSignalForStreaming('slexAircraftExample/Aircraft Dynamics Model',4,'on')

% Simulate system
out_1 = sim('slexAircraftExample');

% Change input filter time constant
modelWorkspace = get_param('slexAircraftExample','modelworkspace');

% Simulate again
out_2 = sim('slexAircraftExample');

Get Signal IDs for the Signal Comparison

Create run objects using the run IDs, and then use getSignalIDByIndex to get the signal IDs to pass to Simulink.sdi.compareSignals.

% Get run data
runIDs = Simulink.sdi.getAllRunIDs;

runID1 = runIDs(end-1);
runID2 = runIDs(end);

run1 = Simulink.sdi.getRun(runID1);
run2 = Simulink.sdi.getRun(runID2);

sigID1 = getSignalIDByIndex(run1,1);
sigID2 = getSignalIDByIndex(run2,1);

Compare Signals

Compare the signals, and open the Simulation Data Inspector to view the results.

diffResult = Simulink.sdi.compareSignals(sigID1,sigID2);


Input Arguments

collapse all

Signal ID for the baseline signal, specified as an integer. The Simulation Data Inspector assigns a signal ID to each signal when a run is created. You can get the signal ID for a signal using one of these functions:

Signal ID for the signal to compare, specified as an integer. The Simulation Data Inspector assigns a signal ID to each signal when a run is created. You can get the signal ID for a signal using one of these functions:

Output Arguments

collapse all

Signal comparison results, returned as a Simulink.sdi.DiffSignalResult object. Complex signal comparison results are returned as an array of two DiffSignalResult objects. One DiffSignalResult object contains the real data and the other contains the imaginary data. Check the Name property of the DiffSignalResult object to determine whether it contains real or imaginary data.


The Simulation Data Inspector does not support comparing:

  • Signals of data types int64 or uint64.

  • Variable-size signals.

Version History

Introduced in R2011b