Simulink.sdi.compareSignals

Compare data from two signals

Description

example

diff = Simulink.sdi.compareSignals(sigID1,sigID2) compares the signals corresponding 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 the comparison of the input and output signals for a control system. The example marks the signals for streaming then gets the run object for a simulation run. Signal IDs from the run object specify the signals to be compared.

% Load model slexAircraftExample and mark signals for streaming
load_system('slexAircraftExample')
Simulink.sdi.markSignalForStreaming('slexAircraftExample/Pilot',1,'on')
Simulink.sdi.markSignalForStreaming('slexAircraftExample/Aircraft Dynamics Model',4,'on')

% Simulate model slexAircraftExample
out = sim('slexAircraftExample');

% Get run IDs for most recent run
allIDs = Simulink.sdi.getAllRunIDs;
runID = allIDs(end);

% Get Run object
aircraftRun = Simulink.sdi.getRun(runID);

% Get signal IDs
signalID1 = getSignalIDByIndex(aircraftRun,1);
signalID2 = getSignalIDByIndex(aircraftRun,2);

if (isValidSignalID(aircraftRun,signalID1))
    % Change signal tolerance
    signal1 = Simulink.sdi.getSignal(signalID1);
    signal1.AbsTol = 0.1;
end

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

    % Check whether signal result status
    match = sigDiff.Status
end
match = 
OutOfTolerance

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. The Simulation Data Inspector assigns signal and run IDs when you create a run for your data. You can access the signal ID from a Simulink.sdi.Run object with the getSignalIDByIndex method.

Signal ID for the Compare to signal. The Simulation Data Inspector assigns signal and run IDs when you create a run for your data. You can access the signal ID from a Simulink.sdi.Run object with the getSignalIDByIndex method.

Output Arguments

collapse all

Simulink.sdi.DiffSignalResult object containing the results of the signal comparison.

Introduced in R2011b