Main Content

Simulink.sdi.CustomSnapshot

Specify settings for snapshot without opening or affecting the Simulation Data Inspector

Description

Use a Simulink.sdi.CustomSnapshot object to specify settings for a snapshot without opening the Simulation Data Inspector or affecting an open session. Creating a snapshot using a Simulink.sdi.CustomSnapshot object is the best option for fully scripted workflows. You can specify the snapshot dimensions in pixels, the subplot layout, and limits for the x- and y- axes. You can use the clearSignals and plotOnSubplot functions to plot signals you want to include in the snapshot. To capture the snapshot, you can pass the Simulink.sdi.CustomSnapshot object as the value for the settings name-value argument for the Simulink.sdi.snapshot object or use the snapshot function.

Creation

Description

snap = Simulink.sdi.CustomSnapshot creates a Simulink.sdi.CustomSnapshot object.

example

Properties

expand all

Image width in pixels, specified as a scalar. The width of the snapshot is constrained by monitor resolution.

Example: 750

Image height in pixels, specified as a scalar. The height of the snapshot is constrained by monitor resolution.

Example: 500

Number of subplot rows, specified as a scalar between 1 and 8, inclusive. Use Rows and Columns to set your desired subplot layout.

When you use the plotComparison function to plot comparison results onto a Simulink.sdi.CustomSnapshot object, the number of rows is 2.

Example: 2

Number of subplot columns, specified as a scalar between 1 and 8, inclusive. Use Rows and Columns to set your desired subplot layout.

When you use the plotComparison function to plot comparison results onto a Simulink.sdi.CustomSnapshot object, the number of columns is 1.

Example: 3

Time axis limits, specified as a 2x1 matrix. The time axis limits in the snapshot are the same for all subplots. By default, the time axis adjusts to accommodate the largest time range of the plotted signals.

When you use the plotComparison function to plot comparison results onto a Simulink.sdi.CustomSnapshot object, a fit-to-view is performed to determine the axis limits.

Example: [0 20]

y-axis limits, specified as a cell array of 1-by-2 matrices specifying the y-axis limits for all subplots in the custom snapshot. By default, YRange is [-3 3] for all subplots.

When you use the plotComparison function to plot comparison results onto a Simulink.sdi.CustomSnapshot object, a fit-to-view is performed to determine the axis limits.

Example: {[-10 10],[0 100]}

Object Functions

clearSignals Clear signals plotted on subplots of Simulink.sdi.CustomSnapshot object
plotOnSubPlot Plot signals on Simulink.sdi.CustomSnapshot object subplots
snapshot Create custom snapshot
plotComparisonPlot comparison results on Simulink.sdi.CustomSnapshot objects

Examples

collapse all

Copy view settings from one run to another and create figures using the Simulink.sdi.CustomSnapshot object.

Simulate Model and Get Run Object

Configure the vdp model to save output data. Run a simulation to create data.

load_system("vdp")
set_param("vdp","SaveFormat","Dataset","SaveOutput","on")
set_param("vdp/Mu","Gain","1");
sim("vdp");

Use the Simulation Data Inspector programmatic interface to access the run data.

runIndex = Simulink.sdi.getRunCount;
runID = Simulink.sdi.getRunIDByIndex(runIndex);
vdpRun = Simulink.sdi.getRun(runID);

Modify Signal View Settings

Use the Simulink.sdi.Run object to access signals in the run. Then, modify the signal view settings. This example specifies the line color and style for each signal. The view settings for the run comprise the view settings for each signal and view settings specified for the plot area.

sig1 = getSignalByIndex(vdpRun,1);
sig2 = getSignalByIndex(vdpRun,2);

sig1.LineColor = [0 0 1];
sig1.LineDashed = "-.";

sig2.LineColor = [1 0 0];
sig2.LineDashed = ":";

Capture Snapshot from Simulation Data Inspector

Create a Simulink.sdi.CustomSnapshot object and use the Simulink.sdi.snapshot function to programmatically capture a snapshot of the contents of the Simulation Data Inspector.

snap = Simulink.sdi.CustomSnapshot;

You can use properties of the Simulink.sdi.CustomSnapshot object to configure the plot settings, such as the subplot layout and axis limits, and to plot signals. When you use a Simulink.sdi.CustomSnapshot object to create your figure, these plot settings do not affect the Simulation Data Inspector.

snap.Rows = 2;
snap.YRange = {[-2.25 2.25],[-3 3]};
plotOnSubPlot(snap,1,1,sig1,true)
plotOnSubPlot(snap,2,1,sig2,true)

Use the Simulink.sdi.snapshot function to generate the figure you specified in the properties of the Simulink.sdi.CustomSnapshot object.

fig = Simulink.sdi.snapshot("From","custom","To","figure","Settings",snap);

Figure contains 2 axes objects. Axes object 1 with xlabel Time (seconds) contains an object of type line. This object represents x1. Axes object 2 with xlabel Time (seconds) contains an object of type line. This object represents x2.

Copy View Settings to New Simulation Run

Simulate the model again, with a different Mu value. Use the Simulation Data Inspector programmatic interface to access the simulation data.

set_param("vdp/Mu","Gain",".5")
sim("vdp");

runIndex2 = Simulink.sdi.getRunCount;
runID2 = Simulink.sdi.getRunIDByIndex(runIndex2);
run2 = Simulink.sdi.getRun(runID2);

To create a plot of the new output data that looks like the one you created in the previous step, you can copy the view settings to the run in a single line of code using the Simulink.sdi.copyRunViewSettings function. This function does not automatically update plot settings in Simulink.sdi.CustomSnapshot objects, so specify the input that determines whether the plot updates as false.

sigIDs = Simulink.sdi.copyRunViewSettings(runID,runID2,false);

Capture Snapshot of New Simulation Run

Use the Simulink.sdi.CustomSnapshot object to capture a snapshot of the new simulation run. First, clear the signals from the subplots. Then, plot the signals from the new run and capture another snapshot.

clearSignals(snap)
snap.YRange = {[-2.25 2.25],[-8 8]};
plotOnSubPlot(snap,1,1,sigIDs(1),true)
plotOnSubPlot(snap,2,1,sigIDs(2),true)


fig = snapshot(snap,"To","figure");

Figure contains 2 axes objects. Axes object 1 with xlabel Time (seconds) contains an object of type line. This object represents x2. Axes object 2 with xlabel Time (seconds) contains an object of type line. This object represents x1.

Version History

Introduced in R2018a