compare

Class: Simulink.sdi.DatasetRef
Package: Simulink.sdi

Compare runs with DatasetRef objects

Syntax

[matches, mismatches, results] = dsrObj.compare(other)

Description

[matches, mismatches, results] = dsrObj.compare(other) returns the number of matches, number of mismatches, and comparison results for a comparison of data in a Simulink.sdi.DatasetRef object. The comparison results are returned as a Simulink.sdi.DiffRunResult object.

Input Arguments

expand all

Comparison data, which can come from another Simulink.sdi.DatasetRef object, a Dataset in the workspace, or a MAT-file.

Example: 'data.mat'

Example: var

Output Arguments

expand all

Number of signals that matched within tolerance in the comparison.

Number of signals that did not match within tolerance in the comparison.

Results of the comparison, returned in a Simulink.sdi.DiffRunResult object.

Examples

expand all

This example shows how to work with the Simulink.sdi.DatasetRef object by comparing two runs of the ex_sldemo_absbrake system with different desired slip ratios.

% Simulate model ex_sldemo_absbrake to create a run of logged signals
load_system('ex_sldemo_absbrake')
sim('ex_sldemo_absbrake')

% Get the runID
runIDs = Simulink.sdi.getAllRunIDs;
runID = runIDs(end);

% Get the run object
brakeRun = Simulink.sdi.getRun(runID);

% Make a Simulink.sdi.DatasetRef object
run_DSRef = brakeRun.getDatasetRef;

% Get the names of the elements in the object
names = run_DSRef.getElementNames
names = 2x1 cell
    {'yout'}
    {'slp' }

% Get yout bus
[yout, name, index] = run_DSRef.getElement(1);

% View signals in outputs
outputs = yout.Values
outputs = struct with fields:
    Ww: [1x1 timeseries]
    Vs: [1x1 timeseries]
    Sd: [1x1 timeseries]

% Get slp signal
slp = run_DSRef.getSignal('slp');

% Plot signal
slp.Checked = 'true';
% Create another run for a different Desired relative slip
set_param('ex_sldemo_absbrake/Desired relative slip', 'Value', '0.25')
sim('ex_sldemo_absbrake')
DSR_Runs = Simulink.sdi.DatasetRef;

% Compare the results from the two runs
[matches, mismatches, diffResult] = run_DSRef.compare(DSR_Runs(2));

% Open the Simulation Data Inspector to view signals
run_DSRef.plot

Alternatives

Using the Simulation Data Inspector API, you could create runs for the data you want to compare and use Simulink.sdi.compareRuns for the comparison. You can also view runs created from simulation, import data to runs, and compare runs with the Simulation Data Inspector UI.

Introduced in R2017b