Simulink.sdi.load

Load a Simulation Data Inspector session or view

Description

example

valid = Simulink.sdi.load(fileName) loads the data in the MLDATX-file or MAT-file specified by fileName and returns 1 when fileName is a valid file. A return value of 0 indicates that the file specified by fileName is invalid and cannot be loaded into the Simulation Data Inspector. You can use Simulink.sdi.load to load Simulation Data Inspector sessions and views. A view includes preferences and visualization options but does not save data. A session saves data along with preference selections and plot configurations.

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

Input Arguments

collapse all

Name of the file to load with the session or view data.

Example: 'myData.mldatx'

Example: 'myData.mat'

Output Arguments

collapse all

Validity indicator for the file. When the file specified by fileName is valid, valid is 1. A valid value of 0 indicates an invalid file.

Introduced in R2011b