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.
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.
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]
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.
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.
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.
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.
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
.
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.