Documentation

Simulink.sdi.DiffRunResult.getResultByIndex

Class: Simulink.sdi.DiffRunResult
Package: Simulink.sdi

Return signal comparison result

Syntax

diffSignalObj = diffRunObj.getResultByIndex(index)

Description

diffSignalObj = diffRunObj.getResultByIndex(index) returns the Simulink.sdi.DiffSignalResult object, diffSignalObj, which contains the comparison results for a signal. diffRunObj is an instance of a Simulink.sdi.DiffRunResult class, which contains an array of signal comparison results, where each element is an instance of a Simulink.sdi.DiffSignalResult class.

Input Arguments

expand all

An index to the array of Simulink.sdi.DiffSignalResult objects contained in a Simulink.sdi.DiffRunResult object, specified as an integer.

Output Arguments

expand all

Results of comparing two signals between simulation runs, returned as a Simulink.sdi.DiffSignalResult object.

Examples

expand all

The function Simulink.sdi.compareRuns returns a Simulink.sdi.DiffRunResult object containing the results of the comparison. The Simulink.sdi.DiffRunResult object contains a Simulink.sdi.DiffSignalResult object for each signal comparison between the two simulation runs. diff.getResultByIndex returns the Simulink.sdi.DiffSignalResult object for each signal comparison.

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

% Create a Simulation Data Inspector run, Simulink.sdi.Run,
% from simOut in the base workspace
runID1 = Simulink.sdi.createRun('First Run','namevalue',{'simOut'},{simOut});

% Simulate again
set_param('slexAircraftExample/Pilot','WaveForm','sawtooth');
simOut = sim('slexAircraftExample','SaveOutput','on',...
             'SaveFormat','StructureWithTime',...
             'ReturnWorkspaceOutputs','on');
      
% Create another Data Inspector run and get signal IDs
runID2 = Simulink.sdi.createRun('Second Run','namevalue',{'simOut'},{simOut});

% Compare two runs and get an instance of Simulink.sdi.DiffRunResult
diff = Simulink.sdi.compareRuns(runID1,runID2);

% Get the number of signal comparison results
count = diff.count;

% Iterate over results and display the comparison results
for i=1:count
	diffSignal = diff.getResultByIndex(i);
	signalID1 = diffSignal.signalID1;
	signalID2 = diffSignal.signalID2;
	match = diffSignal.match;

   if match
      disp([num2str(signalID1) ' and ' num2str(signalID2)...
           ' match']);
   else
      disp([num2str(signalID1) ' and ' num2str(signalID2)...
           ' don''t match']);
   end
end

Related Examples

Introduced in R2012b

Was this topic helpful?