Documentation Center

  • Trial Software
  • Product Updates

Contents

Simulink.sdi.compareSignals

Compare data from two signals

Syntax

diff = Simulink.sdi.compareSignals(signalID1,signalID2)

Description

diff = Simulink.sdi.compareSignals(signalID1,signalID2) compares two signals and returns the results in a Simulink.sdi.DiffSignalsResult object.

Input Arguments

signalID1

Signal ID, a unique number identifying the first signal for comparison.

signalID2

Signal ID, a unique number identifying the second signal for comparison.

Output Arguments

diff

Simulink.sdi.diffSignalsResult object containing the results of the comparison.

Examples

Call Simulink.sdi.createRun to get signal IDs for a simulation run in the Simulation Data Inspector. The function Simulink.sdi.compareSignals returns a Simulink.sdi.DiffSignalResult object containing the result data of the comparison. From this object you can determine if the signals are different.

Comparing two signals:

% Configure model "slexAircraftExample" for logging and simulate
simOut = sim('slexAircraftExample', 'SaveOutput','on', ...
             'SaveFormat', 'StructureWithTime', ...
             'ReturnWorkspaceOutputs','on');

% Create a Simulation Data Inspector run and get signal IDs
[~, ~, signalIDs] = Simulink.sdi.createRun('My Run','namevalue',{'MyData'},{simOut});

sig1 = signalIDs(1);
sig2 = signalIDs(2);

% Compare two signals, which returns results in instance of Simulink.sdi.DiffSignalResult
diff = Simulink.sdi.compareSignals(sig1, sig2);

% Find if the signal data match
match = diff.match;
 
% Get the tolerance used in Simulink.sdi.compareSignals
tolerance = diff.tol;

Comparing signals from two different runs:

% Load the model 'slexAircraftExample'
load_system('slexAircraftExample');
 
% Configure model "slexAircraftExample" for logging
set_param('slexAircraftExample', 'SolverType', 'Fixed-Step', 'SaveOutput','on',  ...
          'SaveFormat', 'StructureWithTime', 'ReturnWorkspaceOutputs', ...
          'on');
  
% CD to temporary directory and build   
cd(tempdir);
rtwbuild('slexAircraftExample');
  
% Run the executable 
if ispc
   system('slexAircraftExample');
elseif unix
   system('./slexAircraftExample');
end
  
% Create a Data Inspector run using slexAircraftExample.mat created in the current
% directory
[~, ~, signalIDs] = Simulink.sdi.createRun('My Run', 'file', 'slexAircraftExample.mat');
  
% Get first signal id to compare
sig1 = signalIDs(1);
  
% Configure model "slexAircraftExample" for logging and simulate
simOut = sim('slexAircraftExample', 'SaveOutput','on', ...
             'SaveFormat', 'StructureWithTime', ...
             'ReturnWorkspaceOutputs', 'on');
 
% Create a Data Inspector run and get signal IDs
[~, ~, signalIDs] = Simulink.sdi.createRun('My Run', 'namevalue',...
                                           {'MyData'}, {simOut});
  
% Get second signal id to compare                                      
sig2 = signalIDs(1);
  
% compare two signals
result = Simulink.sdi.compareSignals(sig1, sig2);
if result.match
   disp('****The signals match****');
else
   disp('****The signals did not match****');
end
  
% Plot results in a figure
plot(result.tol, 'Color', 'r');
hold on;
plot(result.diff, 'Color', 'g');
legend('Tolerance', 'Difference');

See Also

|

Was this topic helpful?