Main Content

Simulink.sdi.save

Save Simulation Data Inspector session

Description

Simulink.sdi.save(fileName) saves all runs, signals, and visualization settings as a Simulation Data Inspector session in the file fileName.

A session file includes data as well as visualization information. Use the Simulink.sdi.load function to open a session file in the Simulation Data Inspector. When the session file opens, you can choose to add the data to existing data in the Simulation Data Inspector or clear the existing data.

You can also save only the visualization information to apply to other sets of data. Save visualization information for reuse in a view file using the Simulink.sdi.saveView function.

example

Simulink.sdi.save(fileName,Name=Value) saves runs, signals, and visualization settings in a session file according to the options specified by name-value pairs. (since R2024b)

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

Save a Simulation Data Inspector session in a MLDATX 2.0 file with the smallest possible file size.

Simulink.sdi.save("mySession.mldatx",Version="2.0",Compression="compact")

Input Arguments

collapse all

Name for the session file.

Example: 'myData.mldatx'

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: Simulink.sdi.save("mySession.mldatx",Version="1.0",Compression="none")

Since R2024b

Session file version, specified as "2.0" or "1.0".

Example: Version="2.0"

Since R2024b

Compression option, specified as one of these options:

  • "fastest" — Similar save speed to an uncompressed file, smaller file size

  • "balanced" — Balance between file size and save speed

  • "compact" — Smallest file size, slowest save speed

  • "none" — Largest file size, fastest save speed

When you save a session file in version 2.0, the default compression option is "fastest". When you save a session file in version 1.0, the default compression option is "none".

Example: Compression="balanced"

Version History

Introduced in R2011b