Main Content

Simulink.sdi.snapshot

R2026b

Capture contents of Simulation Data Inspector plots

Description

fig = Simulink.sdi.snapshot creates a MATLAB figure of the plotting area for the active tab in the Simulation Data Inspector with the Figure object fig. Omit the output argument when you do not need to modify the figure.

example

[fig,image] = Simulink.sdi.snapshot returns the image data in the array, image.

[___] = Simulink.sdi.snapshot(Name=Value) specifies snapshot options using one or more name-value arguments. You can use this syntax with any of the output-argument combinations in previous syntaxes.

example

Examples

collapse all

Create a figure that includes all visible subplots in the Inspect pane of the Simulation Data Inspector and return the figure handle.

fig = Simulink.sdi.snapshot;

A figure window opens containing the plots. You can use the Figure object fig to modify the figure.

To save a snapshot of only the selected subplot in the Simulation Data Inspector, use the From="active" name-value argument. To save the image as a PNG file, use the To="file" name-value argument.

Simulink.sdi.snapshot(From="active",To="file",Filename="myImage.png");

To capture a snapshot of a specific tab, specify the tab index using the TabIndex name-value argument. For example, capture a snapshot of the second tab in the Simulation Data Inspector.

Simulink.sdi.snapshot(TabIndex=2)

Name-Value Arguments

collapse all

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.snapshot(To="figure",Props={"Name","My Data"})

Content to include in the snapshot, specified as one of these options:

  • "opened" — Include all subplots in the open Simulation Data Inspector session.

  • "active" — Include only the active (selected) subplot.

  • "comparison" — Include the comparison plots for the selected comparison run or signal.

  • "custom" — Include contents specified by a Simulink.sdi.CustomSnapshot object. Use the Settings name-value argument to specify the object. When you use From="custom", you can obtain the snapshot without opening the Simulation Data Inspector or affecting an already open session.

Example: From="comparison"

Data Types: char | string

Type of snapshot to create, specified as:

  • "image" — Create a figure and return the corresponding Figure object and an array of image data.

  • "figure" — Create a figure and return the corresponding Figure object. The output has value, and the image output is empty.

  • "file" — Save to a PNG file with the name specified by the Filename name-value argument. If you do not specify a Filename name-value argument, the file is named plots.png. The image outputs are both empty.

  • "clipboard" — Copy the plots to your system clipboard. The image outputs are both empty.

Example: To="file"

Data Types: char | string

Name for image file to store the snapshot when you specify To="file", specified as a string or a character vector.

Example: To="file",Filename="MyImage.png"

Data Types: char | string

Figure properties, specified as a cell array. To customize your figure, you can include settings for the figure properties described in Figure. Specify properties in the form {"Property1","Value1",...,"PropertyN","ValueN"}.

Example: Props={"Name","MyData","NumberTitle","off"}

Data Types: char | string

Since R2026b

Tab index, specified as a positive integer between 1 and 8, inclusive. Tabs are indexed from 1 to 8, left to right. Reordering tabs in the Simulation Data Inspector updates the indices.

You can also locate a tab programmatically using the TabsList property of the Simulink.sdi.TabGroup object. For example, the tab named Tab2 is at index 2.

tabGrp = Simulink.sdi.TabGroup;
allTabs = tabGrp.TabsList;
fprintf("%-10s %-10s %-10s %-10s\n", "Name","Color","Index","IsActive");
for k = 1:numel(allTabs)
    fprintf("%-10s %-10s %-10d %-10d\n",allTabs(k).Name, ...
        allTabs(k).Color,allTabs(k).Index,allTabs(k).IsActive);
end
Name       Color      Index      IsActive  
Tab1       none       1          0         
Tab2       none       2          0         
Tab3       none       3          1    

When you do not specify TabIndex, the function operates on the active tab.

Example: Simulink.sdi.snapshot(TabIndex=2)

Custom snapshot settings, specified as a Simulink.sdi.CustomSnapshot object. Use this name-value argument to specify aspects like the dimensions of the image in pixels, subplot layout, and axes limits.

Example: Settings=customSnap where customSnap is a Simulink.sdi.CustomSnapshot object

Output Arguments

collapse all

Figure, returned as a Figure object. When you save to a file or copy to the clipboard, the fig output is empty.

Image data, returned as an array. Simulink.sdi.snapshot creates an image by default when there are no input arguments or you do not specify the To name-value argument. You can also specify the To="image" name-value argument to create an image. When you explicitly specify To as any value other than "image", the image output argument is empty.

Version History

Introduced in R2018a

expand all