MATLAB Examples

Generate a Simulation Data Inspector Report Programmatically

This example shows how to create reports using the Simulation Data Inspector programmatic interface. You can create a report for plotted signals in the Inspect pane or for comparison data in the Compare pane. This example first generates data by simulating a model, then shows how to create an Inspect Signals report. To run the example exactly as shown, ensure that the Simulation Data Inspector repository starts empty with the docid:simulink_ref.buunt0v function.

Contents

Generate Data

This example generates data using model ex_sldemo_absbrake with two different desired slip ratios.

% Ensure Simulation Data Inspector is empty
Simulink.sdi.clear

% Open model
load_system('ex_sldemo_absbrake')

% Set slip ratio and simulate model
set_param('ex_sldemo_absbrake/Desired relative slip','Value','0.24')
sim('ex_sldemo_absbrake')

% Set new slip ratio and simulate model again
set_param('ex_sldemo_absbrake/Desired relative slip','Value','0.25')
sim('ex_sldemo_absbrake')

Plot Signals in the Inspect Pane

The Inspect Signals report includes all signals plotted in the graphical viewing area of the Inspect pane and all displayed metadata for the plotted signals.

% Get Simulink.sdi.Run objects
runIDs = Simulink.sdi.getAllRunIDs;
runID1 = runIDs(end-1);
runID2 = runIDs(end);

run1 = Simulink.sdi.getRun(runID1);
run2 = Simulink.sdi.getRun(runID2);

% Get Simulink.sdi.Signal objects for slp signal
run1_slp = run1.getSignalByIndex(4);
run2_slp = run2.getSignalByIndex(4);

% Plot slp signals
run1_slp.plotOnSubPlot(1, 1, true)
run2_slp.plotOnSubPlot(1, 1, true)

Create a Report of Signals Plotted in Inspect Pane

You can include more data in the report by adding more columns using the Simulation Data Inspector UI, or you can specify the information you want in the report programmatically with Name-Value pairs and the enumeration class Simulink.sdi.SignalMetaData. This example shows how to specify the data in the report programmatically.

% Specify report parameters
reportType = 'Inspect Signals';
reportName = 'Data_Report.html';


signalMetadata = [Simulink.sdi.SignalMetaData.Run, ...
    Simulink.sdi.SignalMetaData.Line, ...
    Simulink.sdi.SignalMetaData.BlockName, ...
    Simulink.sdi.SignalMetaData.SignalName];

Simulink.sdi.report('ReportToCreate', reportType, 'ReportOutputFile', ...
    reportName, 'ColumnsToReport', signalMetadata);