MATLAB Examples

Compare Simulation Data Inspector Runs Programmatically

This example shows how to compare runs of simulation data and access the comparison results with the Simulation Data Inspector API.

Contents

Generate Runs of Simulation Data

Simulate the model to create runs of simulation data to analyze with the Simulation Data Inspector API.

% Open model
load_system('ex_sldemo_absbrake')

% Set the desired slipratio to 0.24 and simulate
set_param('ex_sldemo_absbrake/Desired relative slip','Value','0.24')
sim('ex_sldemo_absbrake');

% Change the desired slip ratio to 0.25 and simulate
set_param('ex_sldemo_absbrake/Desired relative slip','Value','0.25')
sim('ex_sldemo_absbrake');

Compare Runs

Get the run IDs for the runs you just created with the Simulink.sdi.getAllRunIDs function.

% Get run IDs for last two runs
runIDs = Simulink.sdi.getAllRunIDs;
runID1 = runIDs(end - 1);
runID2 = runIDs(end);

% Compare runs
runResult = Simulink.sdi.compareRuns(runID1, runID2);

Create a Plot of a Comparison Result

Use the Simulink.sdi.DiffRunResult object you created in the previous step with Simulink.sdi.compareRuns to access the data for the Ww signal result to plot it in a figure.

% Plot the |Ww| signal difference
signalResult_Ww = runResult.getResultByIndex(1);
figure(1)
plot(signalResult_Ww.Diff)