Simulink.sdi.clear

Clear all data from the Simulation Data Inspector

Description

example

Simulink.sdi.clear clears all plotted signals and deletes all data from the Simulation Data Inspector. The Simulink.sdi.clear function does not affect preferences or settings you have configured in the Simulation Data Inspector. Use the Simulink.sdi.clearPreferences function to reset the Simulation Data Inspector preferences to their default values. Use the Simulink.sdi.clearAllSubPlots function to clear all plotted signals without deleting any data from the Simulation Data Inspector.

Examples

collapse all

This example shows how to create, save, and load a Simulation Data Inspector session. The example uses data logging to populate the Simulation Data Inspector with data and then uses the Simulation Data Inspector's programmatic interface to create plots to visualize the data. After saving the data and visualization settings in a session, the Simulation Data Inspector repository is emptied in order to demonstrate how to load the session.

Create Simulation Data

This example logs the Stick, alpha, rad, and q, rad/sec signals to generate simulation data using the model slexAircraftExample and creates two runs. The first uses a sine input, and the second has a square wave input.

% Ensure you start with an empty Simulation Data Inspector repository
Simulink.sdi.clear

% Load system
load_system('slexAircraftExample')

% Configure signals to log
Simulink.sdi.markSignalForStreaming('slexAircraftExample/Pilot',1,'on')
Simulink.sdi.markSignalForStreaming('slexAircraftExample/Aircraft Dynamics Model',3,'on')
Simulink.sdi.markSignalForStreaming('slexAircraftExample/Aircraft Dynamics Model',4,'on')

% Change Pilot signal to sine
set_param('slexAircraftExample/Pilot','WaveForm','sine')

% Simulate model
sim('slexAircraftExample')

% Change Pilot signal to square
set_param('slexAircraftExample/Pilot','WaveForm','square')

% Simulate model
sim('slexAircraftExample')

Access Simulation Data

Use the Simulation Data Inspector programmatic interface to access the simulation data so you can create plots to visualize the signals.

% Get run objects
runIDs = Simulink.sdi.getAllRunIDs;
sineRunID = runIDs(end-1);
squareRunID = runIDs(end);

sineRun = Simulink.sdi.getRun(sineRunID);
squareRun = Simulink.sdi.getRun(squareRunID);

% Get signal objects
sineOut = sineRun.getSignalByIndex(1);
sineIn = sineRun.getSignalByIndex(3);

squareOut = squareRun.getSignalByIndex(1);
squareIn = squareRun.getSignalByIndex(3);

Create Plots in the Simulation Data Inspector

Use the programmatic interface to visualize the signal data from the two simulation runs. You can set the plot layout and plot signals on specific subplots.

% Set subplot layout 
Simulink.sdi.setSubPlotLayout(2,1)

% Plot sine data on top plot
sineIn.plotOnSubPlot(1,1,true)
sineOut.plotOnSubPlot(1,1,true)

% Plot square wave data on bottom plot
squareIn.plotOnSubPlot(2,1,true)
squareOut.plotOnSubPlot(2,1,true)

Save a Simulation Data Inspector Session

First, view the plots you just created. Then, save the Simulation Data Inspector session as an MLDATX-file to recover your data along with your preference selections and plots.

% View the visualized data in the Simulation Data Inspector
Simulink.sdi.view

% Save the Simulation Data Inspector session
Simulink.sdi.save('myData.mldatx')

Load a Simulation Data Inspector Session

First, clear the Simulation Data Inspector repository with Simulink.sdi.clear and reset visualization settings with Simulink.sdi.clearPreferences. Then, you can load the session to see how the data and settings are preserved.

% Clear Simulation Data Inspector repository and preferences
Simulink.sdi.clear
Simulink.sdi.clearPreferences

% Load session file to view data
Simulink.sdi.load('myData.mldatx');

Introduced in R2011b