Main Content

Simulink.sdi.CustomSnapshot

R2026b

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

Description

Use a Simulink.sdi.CustomSnapshot object to specify signals and 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, the subplot layout, and axis limits. You can use the clearSignals and plotOnSubPlot functions to specify signals you want to include in the snapshot. To capture the snapshot, either:

  • Use Simulink.sdi.snapshot, setting the Settings option to the Simulink.sdi.CustomSnapshot object

  • Use the snapshot with the object

Creation

Description

snap = Simulink.sdi.CustomSnapshot creates a Simulink.sdi.CustomSnapshot object with default property values. Use dot notation to customize snapshot options after creation.

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

Create a default Simulink.sdi.CustomSnapshot object.

snapObj = Simulink.sdi.CustomSnapshot;

To configure plot settings in the snapshot, modify the object properties. For example, create a 3-by-1 subplot layout and specify the range of each subplot in columnwise order.

snapObj.Rows = 3;
snapObj.Columns = 1;
snapObj.YRange = {[-1 1],[-2 2],[-3 3]}; 

Suppose that you want the subplots to show three particular signals from the most recent run. First, access those signals.

myRun = Simulink.sdi.Run.getLatest;
sig1 = getSignalByIndex(myRun,1);
sig2 = getSignalByIndex(myRun,2);
sig3 = getSignalByIndex(myRun,3);

To configure the custom snapshot to include these signals, use plotOnSubPlot.

plotOnSubPlot(snapObj,1,1,sig1,true)
plotOnSubPlot(snapObj,2,1,sig2,true)
plotOnSubPlot(snapObj,3,1,sig3,true)

Generate the figure. Using snapshot with the CustomSnapshot object generates the figure without affecting what is currently plotted in the Simulation Data Inspector.

fig = snapshot(snapObj)

Figure of three signals plotted in a 3-by-1 subplot layout.

Version History

Introduced in R2018a