getResultByIndex
Return signal comparison result
Description
Examples
Analyze Simulation Data Using Signal Tolerances
You can programmatically specify signal tolerance values to use in comparisons performed using the Simulation Data Inspector. In this example, you compare data collected by simulating a model of an aircraft longitudinal flight control system. Each simulation uses a different value for the input filter time constant and logs the input and output signals. You analyze the effect of the time constant change by comparing results using the Simulation Data Inspector and signal tolerances.
First, load the session file that contains the simulation data.
Simulink.sdi.load('AircraftExample.mldatx');
The session file contains four runs. In this example, you compare data from the first two runs in the file. Access the Simulink.sdi.Run
objects for the first two runs loaded from the file.
runIDs = Simulink.sdi.getAllRunIDs; runIDTs1 = runIDs(end-3); runIDTs2 = runIDs(end-2);
Compare the two runs without specifying any tolerances.
noTolDiffResult = Simulink.sdi.compareRuns(runIDTs1,runIDTs2);
Use the getResultByIndex
function to access the comparison results for the q
and alpha
signals.
qResult = getResultByIndex(noTolDiffResult,1); alphaResult = getResultByIndex(noTolDiffResult,2);
Check the Status
property of each signal result to see whether the comparison result falls within or out of tolerance.
qResult.Status
ans = ComparisonSignalStatus enumeration OutOfTolerance
alphaResult.Status
ans = ComparisonSignalStatus enumeration OutOfTolerance
The comparison uses a value of 0
for all tolerances, so the OutOfTolerance
result means the signals are not identical.
You can further analyze the effect of the time constant by specifying tolerance values for the signals. Specify the tolerances by setting the properties for the Simulink.sdi.Signal
objects that correspond to the signals being compared. Comparisons use tolerances specified for the baseline signals. This example specifies a time tolerance and an absolute tolerance.
To specify a tolerance, first access the Signal
objects from the baseline run.
runTs1 = Simulink.sdi.getRun(runIDTs1); qSig = getSignalsByName(runTs1,'q, rad/sec'); alphaSig = getSignalsByName(runTs1,'alpha, rad');
For the q
signal, specify an absolute tolerance of 0.1
and a time tolerance of 0.6
using the AbsTol
and TimeTol
properties, respectively.
qSig.AbsTol = 0.1; qSig.TimeTol = 0.6;
For the alpha
signal, specify an absolute tolerance of 0.2
and a time tolerance of 0.8
.
alphaSig.AbsTol = 0.2; alphaSig.TimeTol = 0.8;
Compare the results again. Access the results from the comparison and check the Status
property for each signal.
tolDiffResult = Simulink.sdi.compareRuns(runIDTs1,runIDTs2); qResult2 = getResultByIndex(tolDiffResult,1); alphaResult2 = getResultByIndex(tolDiffResult,2); qResult2.Status
ans = ComparisonSignalStatus enumeration WithinTolerance
alphaResult2.Status
ans = ComparisonSignalStatus enumeration WithinTolerance
Input Arguments
diffRes
— Run comparison results
Simulink.sdi.DiffRunResult
object
Run comparison results that contain the signal result you want to access,
specified as a Simulink.sdi.DiffRunResult
object.
index
— Index of signal in run comparison results
integer
Index of signal in run comparison results, specified as an integer.
Example: 2
Output Arguments
diffSig
— Comparison results for signal at specified index
Simulink.sdi.DiffSignalResult
object
Comparison results for the signal at the specified index, returned as a
Simulink.sdi.DiffSignalResult
object.
Version History
Introduced in R2012b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)