Simulink.sdi.compareSignals

Compare data in two Simulink.sdi.Signal objects

Description

example

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.

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.

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
load_system('slexAircraftExample')

% 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');
assignin(modelWorkspace,'Ts',0.2)

% 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);

Simulink.sdi.view

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.

Introduced in R2011b