Simulink.sdi.compareSignals
Compare data in two Simulink.sdi.Signal
objects
Syntax
Description
compares the signals that correspond to the signal IDs diff
= Simulink.sdi.compareSignals(sigID1
,sigID2
)sigID1
and
sigID2
and returns the results in a Simulink.sdi.DiffSignalResult
object. For more information on how the comparison results are computed, see How the Simulation Data Inspector Compares Data.
compares the signals that correspond to the signal IDs diff
= Simulink.sdi.compareSignals(sigID1
,sigID2
,Name=Value
)sigID1
and
sigID2
using the options specified by one or more name-value
arguments. (since R2023a)
Examples
Compare Two Signals in the Same Run
You can use the Simulation Data Inspector programmatic interface to compare signals within a single run. This example compares the input and output signals of an aircraft longitudinal flight controller.
Load the Simulation Data Inspector session file that contains the flight control data.
Simulink.sdi.load("AircraftExample.mldatx");
To access the latest run, use the Simulink.sdi.Run.getLatest
function.
aircraftRun = Simulink.sdi.Run.getLatest;
Use the Simulink.sdi.getSignalsByName
function to access the Stick
signal, which represents the input to the controller, and the alpha, rad
signal, which represents the output.
stick = getSignalsByName(aircraftRun,"Stick"); alpha = getSignalsByName(aircraftRun,"alpha, rad");
Use the signal IDs to compare the Stick
and alpha, rad
signals using the Simulink.sdi.compareSignals
function. The Stick
signal is the baseline. The alpha, rad
signal is the signal to compare against the baseline.
comparisonResults = Simulink.sdi.compareSignals(stick.ID,alpha.ID); match = comparisonResults.Status
match = ComparisonSignalStatus enumeration OutOfTolerance
The comparison result is out of tolerance. You can use the Simulink.sdi.view
function to open the Simulation Data Inspector to view and analyze the comparison results.
Simulink.sdi.view
You can specify time and magnitude tolerance values to use for the comparison. Comparisons use tolerance values specified for the baseline signal in the comparison. To account for the phase shift, set a time tolerance of 1
on the Stick
signal. To account for magnitude differences, set an absolute tolerance value of 0.1
on the Stick
signal.
stick.TimeTol = 1; stick.AbsTol = 0.1;
Compare the signals again. This time, because of the absolute and time tolerances, the signal comparison passes.
comparisonResults = Simulink.sdi.compareSignals(stick.ID,alpha.ID); match = comparisonResults.Status
match = ComparisonSignalStatus enumeration WithinTolerance
Compare Signals from Different Runs
This example shows how to compare signals from different simulation runs using the Simulation Data Inspector's Simulink.sdi.compareSignals
function. When you only have one signal of interest to compare, using a signal comparison returns the Simulink.sdi.diffSignalResult
object with the comparison data directly.
Generate Simulation Data
Use the slexAircraftExample
model to generate simulation runs. Between the runs, change the time constant of the input filter.
% Load example model load_system('slexAircraftExample') % Mark the alpha, rad signal for streaming Simulink.sdi.markSignalForStreaming('slexAircraftExample/Aircraft Dynamics Model',4,'on') % Simulate system out_1 = sim('slexAircraftExample'); % Change input filter time constant modelWorkspace = get_param('slexAircraftExample','modelworkspace'); assignin(modelWorkspace,'Ts',0.2) % Simulate again out_2 = sim('slexAircraftExample');
Get Signal IDs for the Signal Comparison
Create run objects using the run IDs, and then use getSignalIDByIndex
to get the signal IDs to pass to Simulink.sdi.compareSignals
.
% Get run data
runIDs = Simulink.sdi.getAllRunIDs;
runID1 = runIDs(end-1);
runID2 = runIDs(end);
run1 = Simulink.sdi.getRun(runID1);
run2 = Simulink.sdi.getRun(runID2);
sigID1 = getSignalIDByIndex(run1,1);
sigID2 = getSignalIDByIndex(run2,1);
Compare Signals
Compare the signals, and open the Simulation Data Inspector to view the results.
diffResult = Simulink.sdi.compareSignals(sigID1,sigID2); Simulink.sdi.view
Input Arguments
sigID1
— Signal ID of baseline signal
integer
Signal ID of baseline signal, specified as an integer. The Simulation Data Inspector assigns a signal ID to each signal when a run is created. You can get the signal ID for a signal using one of these functions:
sigID2
— Signal ID of signal to compare
integer
Signal ID of signal to compare, specified as an integer. The Simulation Data Inspector assigns a signal ID to each signal when a run is created. You can get the signal ID for a signal using one of these functions:
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose
Name
in quotes.
Example: diff =
Simulink.sdi.compareSignals(sigID1,sigID2,DataType="MustMatch")
DataType
— Comparison sensitivity to signal data types
"MustMatch"
Comparison sensitivity to signal data types, specified as
"MustMatch"
. Specify
DataType="MustMatch"
when you want the comparison
to be sensitive to numeric data type mismatches in compared
signals.
When signal data types do not match, the Status
property of the Simulink.sdi.DiffSignalResult
object for the result is set
to DataTypeMismatch
.
The Simulink.sdi.compareSignals
function compares
the data types before synchronizing and comparing the signal data. When
you do not specify this name-value argument, the comparison checks data
types only to detect a comparison between string and numeric data. For a
comparison between string and numeric data, results are not computed,
and the status for the result is DataTypeMismatch
.
For signals that have different numeric data types, the comparison
computes results.
When you configure the comparison to stop on the first mismatch, a data type mismatch stops the comparison.
Time
— Comparison sensitivity to signal time vectors
"MustMatch"
Comparison sensitivity to signal time vectors, specified as
"MustMatch"
. Specify
Time="MustMatch"
when you want the comparison to
be sensitive to mismatches in the time vectors of compared signals. When
you specify this name-value argument, the algorithm compares the time
vectors before synchronizing and comparing the signal data.
When the time vectors do not match, the Status
property of the Simulink.sdi.DiffSignalResult
object for the result is set
to TimeMismatch
.
Comparisons are not sensitive to differences in signal time vectors unless you specify this name-value argument. For comparisons that are not sensitive to differences in the time vectors, the comparison algorithm synchronizes the signals prior to the comparison. For more information about how synchronization works, see How the Simulation Data Inspector Compares Data.
When you specify that time vectors must match and configure the comparison to stop on the first mismatch, a time vector mismatch stops the comparison.
StartStop
— Comparison sensitivity to signal start and stop times
"MustMatch"
Comparison sensitivity to signal start and stop times, specified as
"MustMatch"
. Specify
StartStop="MustMatch"
when you want the
comparison to be sensitive to mismatches in signal start and stop times.
When you specify this name-value argument, the algorithm compares the
start and stop times for each signal before synchronizing and comparing
the signal data.
When the start times and stop times do not match, the
Status
property of the Simulink.sdi.DiffSignalResult
object for the result is set
to StartStopMismatch
.
When you specify that start and stop times must match and configure the comparison to stop on the first mismatch, a start or stop time mismatch stops the comparison.
StopOnFirstMismatch
— Whether comparison stops on first detected mismatch
"Metadata"
| "Any"
Whether comparison stops on first detected mismatch, specified as
"Metadata"
or "Any"
. A stopped
comparison may not compute results for all channels when comparing
multidimensional signals and can return a mismatched result more
quickly.
"Metadata"
— A mismatch in metadata stops the comparison. Metadata comparisons happen before signal data comparisons.The Simulation Data Inspector always compares signal units. When you configure the comparison to stop on the first mismatch, mismatched units always stop the comparison. You can specify additional name-value arguments to configure the comparison to check and stop on the first mismatch for additional metadata, such as signal data type, start and stop times, and time vectors.
"Any"
— A mismatch in metadata or signal data stops the comparison.
ExpandChannels
— Whether to compute comparison results for each channel in multidimensional signals
false
or
0
(default) | true
or 1
Whether to compute comparison results for each channel in
multidimensional signals, specified as logical true
(1
) or false
(0
).
true
or1
— Comparison expands multidimensional signals represented as a single signal with nonscalar sample values to a set of signals with scalar sample values and computes a comparison result for each signal.The representation of the multidimensional signal in the Simulation Data Inspector as a single signal with nonscalar sample values does not change.
false
or0
— Comparison does not compute results for multidimensional signals represented as a single signal with nonscalar sample values.
Output Arguments
diff
— Signal comparison result
Simulink.sdi.diffSignalResult
| array of Simulink.sdi.diffSignalResult
objects
Signal comparison result, returned as a Simulink.sdi.DiffSignalResult
object. Complex signal
comparison results are returned as an array of two
DiffSignalResult
objects. One
DiffSignalResult
object contains the real data and the
other contains the imaginary data. Check the Name
property of the DiffSignalResult
object to determine
whether it contains real or imaginary data.
Limitations
The Simulation Data Inspector does not support comparing:
Before R2020a: Signals of data types
int64
oruint64
.Variable-size signals.
If you perform multiple signal comparisons or run comparisons, only the latest
DiffSignalResult
object has visible properties.
Version History
Introduced in R2011b
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 (한국어)