This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Inspect and Compare Data Programmatically

You can harness the capabilities of the Simulation Data Inspector from the MATLAB® command line using the Simulation Data Inspector API. The API enables you to execute your workflow, from populating the Simulation Data Inspector with data to analyzing comparison results.

Create a Run from Workspace Variables

This example creates a run in the Simulation Data Inspector from variables in the base workspace and plots the signals.

% Create timeseries data
t = (0:0.1:2*pi)';
ts1 = timeseries(sin(t),t,'Name','sine');
ts2 = timeseries(cos(t),t,'Name','cosine');

% Import timeseries into the Simulation Data Inspector
runID = Simulink.sdi.createRun('My Run','vars',ts1,ts2);
run = Simulink.sdi.getRun(runID);

% Plot signals
sig1 = getSignalByIndex(run,1);
sig2 = getSignalByIndex(run,2);

sig1.checked = true;
sig2.checked = true;

% Open the Simulation Data Inspector

Compare Signals Programmatically

You can programmatically compare signals using the Simulation Data Inspector.

% Open model

% Simulate model

% Create a Simulation Data Inspector run
runID = Simulink.sdi.getRunIDByIndex(1);
run = Simulink.sdi.getRun(runID);

sig1 = getSignalIDByIndex(run,1);
sig2 = getSignalIDByIndex(run,2);

% Compare two signals
diff = Simulink.sdi.compareSignals(sig1,sig2);

% Find if signal data match
Match = diff.Match;

Compare Runs of Simulation Data

This example compares the signal data of two simulation runs. At the end of this example, the difference between the Ww signal from each run is plotted in a MATLAB figure.

% Open model

% Simulate model using 0.24 desired slip
set_param('sldemo_absbrake/Desired relative slip','Value','0.24')

% Simulate model using 0.25 desired slip
set_param('sldemo_absbrake/Desired relative slip','Value','0.25')

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

% Plot 'Ww' signal difference between runs
signalResult = getResultByIndex(runResult, 1);

Analyze Simulation Data with Signal Tolerances

You can change tolerance values on a signal by signal basis to evaluate the effect of a model parameter change. This example uses the slexAircraftExample model and the Simulation Data Inspector to evaluate the effect of changing the time constant for the low-pass filter following the control input.

% Load example model

% Mark the alpha, rad signal for streaming
Simulink.sdi.markSignalForStreaming('slexAircraftExample/Aircraft Dynamics Model', 4, 'on')

% Simulate system

% Change input filter time constant
modelWorkspace = get_param('slexAircraftExample', 'modelworkspace');
modelWorkspace.assignin('Ts', 0.2)

% Simulate again

% Get run data
runID1 = Simulink.sdi.getRunIDByIndex(1);
run1 = Simulink.sdi.getRun(runID1);

runID2 = Simulink.sdi.getRunIDByIndex(2);
run2 = Simulink.sdi.getRun(runID2);

% Compare signals
sigID1 = run1.getSignalIDByIndex(1);
sigID2 = run2.getSignalIDByIndex(1);
diff1 = Simulink.sdi.compareSignals(sigID1, sigID2);

% Check comparison result
ans =



The result indicates that the signals do not match with the default tolerance of zero. You can change the tolerance and run the comparison again to evaluate the effect of the change in time constant.

% Get signal object for sigID1
sig1 = Simulink.sdi.getSignal(sigID1);

% Change absolte tolerance to 0.2
sig1.absTol = 0.2;

% Run the comparison again
diff2 = Simulink.sdi.compareSignals(sigID1, sigID2);

% Check the result
ans =



Generate a Report from the Simulation Data Inspector

You can programmatically generate a report from the Simulation Data Inspector.

% Open model

% Simulate model twice
set_param('sldemo_absbrake/Desired relative slip','Value','0.22')

set_param('sldemo_absbrake/Desired relative slip','Value','0.25')

% Compare two runs
runID1 = Simulink.sdi.getRunIDByIndex(1);
runID2 = Simulink.sdi.getRunIDByIndex(2);

% Create report'ReportToCreate','Compare Runs')

Clear All Logged Signals

You can programmatically stop logging all signals marked for logging within a model. With a clean slate, you can then select your particular signals of interest to log and inspect in the Simulation Data Inspector.

This example starts by clearing all logged signals and then marks the EngineRPM and Gear signals for logging.

% Load example system

% Clear all logged signals
set_param('sldemo_autotrans', 'InstrumentedSignals', [])

% Mark EngineRPM and Gear signals for logging
Simulink.sdi.markSignalForStreaming('sldemo_autotrans/ShiftLogic', 1, 'on')
Simulink.sdi.markSignalForStreaming('sldemo_autotrans/Engine', 1, 'on')

% Simulate the model

% View logged signals in the Simulation Data Inspector

Related Topics

Was this topic helpful?