rect=getgcapixelsize
rect : | [left bottom width height] in pixels |
subplot(2,2,2)
rect=getgcapixelsize
I=getframe(gcf,rect); figure(3333); imshow(I.cdata);
This function, getgcapixelsize
, calculates the pixel size and position of the current axes (gca) within a figure in MATLAB. It is useful when the getframe(gca)
function does not work as expected.
The function does not take any input parameters.
The function returns a vector rect
which contains four elements: [left, bottom, width, height] in pixels.
get(gca, 'Position')
. This returns a vector app
with four elements: [left, bottom, width, height] in percentage.get(get(gca, 'Parent'), 'InnerPosition')
. This returns a vector fp
with four elements: [left, bottom, width, height] in pixels.ap = [app(1)*fp(3), app(2)*fp(4), app(3)*fp(3), app(4)*fp(4)]
.round(ap)
to get the final pixel position and size of the axes.rect
.The function can be used in a MATLAB script as follows:
subplot(2,2,2)
rect = getgcapixelsize;
I = getframe(gcf, rect);
figure(3333);
imshow(I.cdata);
In this example, a subplot is created, and the pixel size of the axes is obtained using getgcapixelsize
. The getframe
function is then used to capture the content of the axes, and the captured image is displayed in a new figure.