Documentation

Simulink.sdi.compareSignals

Compare data from two signals

Syntax

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

Description

example

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

Examples

collapse all

Compare Two Signals

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.

% 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 a Simulink.sdi.DiffSignalResult object
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;

Compare 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');

Related Examples

Input Arguments

collapse all

signalID1 — Unique signal identifierinteger

Signal ID, a unique number identifying the first signal for comparison, specified as an integer.

signalID2 — Unique signal identifierinteger

Signal ID, a unique number identifying the first signal for comparison, specified as an integer.

Output Arguments

collapse all

diff — Comparison difference dataobject

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

Introduced in R2011b

Was this topic helpful?