Main Content

Simulink.sdi.load

Load a Simulation Data Inspector session or view

Description

valid = Simulink.sdi.load(fileName) loads the data and visualization settings in the Simulation Data Inspector session file or MAT file specified by fileName and returns 1 when fileName is a valid session file or a MAT file that contains data the Simulation Data Inspector supports.

Simulation Data Inspector views are also saved as MLDATX files. To load a view file, use the Simulink.sdi.loadView function.

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

Input Arguments

collapse all

Name of the session file or MAT file to load, specified as a strong or character vector. You must specify the file extension to load data from an MLDATX file.

Example: 'myData.mldatx'

Example: 'myData.mat'

Output Arguments

collapse all

File validity indicator, returned as 1 (true) or 0 (false). A return value of 0 indicates that the Simulation Data Inspector did not load the session file or did not import data from the MAT file.

Version History

Introduced in R2011b