getframe
Captures an image of a figure.
Syntax
f = getframe()
f = getframe(handle)
f = getframe(handle, position)
Inputs
- handle
- Handle of a figure or an axes element. In case an axes handle is provided then the capture area will not include the x and y axes (for 2D plots). If a handle is not provided then the current axes will be captured.
- position
- A 4-element vector in the form [left top width height] which specifies the figure or axes area to capture. Note that the x, y, width and height values are in pixels regardless of the 'units' type of the figure/axes.
Outputs
- f
- A struct which contains the field 'cdata'. The value of 'cdata' is an MxNx3 matrix - the r,g,b values of each pixel of the captured image.
Example
getframe example:
figure(1, 'position',[0 0 500 300]);
undock;
plot(rand(10,2),'-o');
set(gca,'position',[0.1 0.1 0.8 0.8]);
% capture figure
im1 = getframe(1);
% capture axes
im2 = getframe(gca);
% capture a part of the figure
im3 = getframe(1,[1 1 250 150]);