This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Simulink.sdi.snapshot

Capture contents of Simulation Data Inspector plots

Syntax

fig = Simulink.sdi.snapshot
[fig,image] = Simulink.sdi.snapshot
Simulink.sdi.snapshot(Name,Value)
Simulink.sdi.snapshot(Name,Value)
Simulink.sdi.snapshot(Name,Value)

Description

fig = Simulink.sdi.snapshot creates a figure of the plotting area in the open Simulation Data Inspector session with the figure handle fig.

[fig,image] = Simulink.sdi.snapshot creates a figure of the plotting area in the open Simulation Data Inspector session with the figure handle fig and returns the image data in the array, image.

Simulink.sdi.snapshot(Name,Value) captures an image of the Simulation Data Inspector plots according to the options specified by name-value pairs.

example

fig = Simulink.sdi.snapshot(Name,Value) captures an image of the Simulation Data Inspector plots according to the options specified by name-value pairs. This syntax returns the figure handle, fig, if a figure is created.

[fig, image] = Simulink.sdi.snapshot(Name,Value) captures an image of the Simulation Data Inspector plots according to the options specified by name-value pairs. This syntax returns the figure handle, fig, and an array of image data, image, when appropriate for the specified options.

Examples

collapse all

This example shows how to copy the view settings for aligned signals from one run to another.

Simulate Your Model and get Run Object

Simulate the vdp model to create a run of data to visualize.

load_system('vdp')
set_param('vdp','SaveFormat','Dataset','SaveOutput','on')
sim('vdp')

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

Modify View Settings for Signals

Use the Simulink.sdi.Run object to access the signals in the run. Then, modify the signals' view settings, and plot them in the Simulation Data Inspector. Open the Simulation Data Inspector and use Simulink.sdi.snapshot to view the results.

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

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

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

Capture a Snapshot from the 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;

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

fig = Simulink.sdi.snapshot("from","custom","to","figure","settings",snap);

Copy the View Settings to a New Simulation Run

Simulate the model again, with a different Mu value. Then, visualize the new run by copying the view settings from the first run. Specify the plot input as true to plot the signals from the new run.

set_param('vdp/Mu','Gain','5')
sim('vdp')

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

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

Capture a Snapshot of the 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.

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

fig = snap.snapshot("to","figure");

Input Arguments

collapse all

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'to','figure','props',{'Name','My Data'}

Content to include in the snapshot.

  • 'opened' — Include all subplots in the graphical viewing area of the open Simulation Data Inspector session.

  • 'active' — Include only the active (selected) subplot in the open Simulation Data Inspector session.

  • 'comparison' — Include the comparison plots for the selected comparison run or signal in the open Simulation Data Inspector session.

  • 'custom' — Include contents specified by the settings name-value pair Simulink.sdi.CustomSnapshot object. You can use the 'from','custom' option to create a snapshot without opening the Simulation Data Inspector or affecting your open Simulation Data Inspector session. Include a settings name-value pair when you specify 'from','custom'.

Example: 'from','comparison'

Data Types: char | string

Type of snapshot to create.

  • 'image' — Create a figure and return the figure handle and an array of image data. When you specify 'to','image', the fig and image outputs both have value.

  • 'figure' — Create a figure and return the figure handle. When you specify 'to','figure' the fig output has value, and the image output is empty.

  • 'file' — Save to a PNG file with the name specified by the filename name-value pair. If you do not specify a filename name-value pair, the file is named plots.png. When you specify 'to','file', the fig and image outputs are both empty.

  • 'clipboard' — Copy the plots to your system clipboard. From the clipboard, you can paste the image into another program such as Microsoft® Word. When you specify 'to','clipboard', the fig and image outputs are both empty.

Example: 'to','file'

Data Types: char | string

Name of the image file to store the snapshot when you specify 'to','file'.

Example: 'filename','MyImage.png'

Data Types: char | string

Figure properties, specified as a cell array. You can include settings for the figure properties described in Figure Properties.

Example: 'props',{'Name','MyData','NumberTitle','off'}

Data Types: char | string

Simulink.sdi.CustomSnapshot object specifying custom snapshot settings. You can use the settings name-value pair to specify the dimensions of the image in pixels, subplot layout, and limits for the x- and y-axes.

Example: 'settings',customSnap

Data Types: char | string

Output Arguments

collapse all

Handle for the figure. When a figure is not created with your specified options, the fig output is empty.

Array of image data. The image output has value when you use Simulink.sdi.snapshot without any input arguments or without a to name-value pair and when you specify 'to','image'.

Introduced in R2018a