Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Simulink.sdi.compareSignals

Compare data from two signals

Syntax

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

Description

example

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

Examples

collapse all

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 of the comparison.

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

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

Input Arguments

collapse all

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

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

Output Arguments

collapse all

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

Introduced in R2011b

Was this topic helpful?