Main Content

Simulink.sdi.clear

Clear all data from the Simulation Data Inspector

Description

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.

example

Examples

collapse all

This example creates, saves, and loads a Simulation Data Inspector session. The example logs data in the model slexAircraftExample and visualizes the logged data in a Simulation Data Inspector session. Each time you use the Simulation Data Inspector, you create and modify a session. You can save the data and associated visualization settings for a session in an MLDATX file using the Simulink.sdi.save function. When you want to review the data later, you can load the session using the Simulink.sdi.load function.

Log Data to the Simulation Data Inspector

This example logs data from a simulation of the model slexAircraftExample to the Simulation Data Inspector. The model is not configured to log data. Load the model and mark the Stick, the alpha, rad, and the q, rad/sec signals for logging.

load_system('slexAircraftExample')

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')

For this example, run two simulations of the model. In the first simulation, use the sine wave output from the Pilot block, and in the second, use the square wave output.

set_param('slexAircraftExample/Pilot','WaveForm','sine')
sim('slexAircraftExample')
ans = 
  Simulink.SimulationOutput:
                logsout: [1x1 Simulink.SimulationData.Dataset] 
                   tout: [1235x1 double] 
                   xout: [1x1 Simulink.SimulationData.Dataset] 
                   yout: [1x1 Simulink.SimulationData.Dataset] 

     SimulationMetadata: [1x1 Simulink.SimulationMetadata] 
           ErrorMessage: [0x0 char] 

set_param('slexAircraftExample/Pilot','WaveForm','square')
sim('slexAircraftExample')
ans = 
  Simulink.SimulationOutput:
                logsout: [1x1 Simulink.SimulationData.Dataset] 
                   tout: [1381x1 double] 
                   xout: [1x1 Simulink.SimulationData.Dataset] 
                   yout: [1x1 Simulink.SimulationData.Dataset] 

     SimulationMetadata: [1x1 Simulink.SimulationMetadata] 
           ErrorMessage: [0x0 char] 

Visualize the Logged Data

You can use the Simulation Data Inspector programmatic interface to access the logged data from the simulations. When you access data using the Simulation Data Inspector programmatic interface, you can use functions to create plots in the Simulation Data Inspector.

To start, access the run IDs for the most recent two runs and then get the corresponding Simulink.sdi.Run object. The Run objects allow you to access the logged data for the simulations.

runIDs = Simulink.sdi.getAllRunIDs;
sineRunID = runIDs(end-1);
squareRunID = runIDs(end);

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

Suppose you want to analyze the relationship between the input and output for the model. Get the Simulink.sdi.Signal objects for the input and output signals from the two simulation runs.

sineOut = getSignalByIndex(sineRun,1);
sineIn = getSignalByIndex(sineRun,3);

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

Change the subplot layout in the Simulation Data Inspector to 2-by-1 and plot the signals from the first simulation run on the top plot and the signals from the second run on the bottom plot.

Simulink.sdi.setSubPlotLayout(2,1)

plotOnSubPlot(sineIn,1,1,true)
plotOnSubPlot(sineOut,1,1,true)

plotOnSubPlot(squareIn,2,1,true)
plotOnSubPlot(squareOut,2,1,true)

Save the Simulation Data Inspector Session

To view the plotted data in the Simulation Data Inspector, enter Simulink.sdi.view in the command window.

Then, save the Simulation Data Inspector session as an MLDATX file.

Simulink.sdi.save('myData.mldatx')

Load the Simulation Data Inspector Session

To mimic a scenario where you want to return to looking at the same data at a later point, clear the data from the Simulation Data Inspector and reset the subplot layout to 1-by-1.

Simulink.sdi.clear
Simulink.sdi.setSubPlotLayout(1,1)

Load the session file and resume working with the data. You can open the Simulation Data Inspector and view the results using the Simulink.sdi.view function.

Simulink.sdi.load('myData.mldatx');

Version History

Introduced in R2011b