F = getframe;
F = getframe(ax) 坐标轴对象;
F = getframe(fig) 图形对象;
F = getframe(__,rect) 捕获rect定义的矩形区域 , rect [left bottom width height]
plot(rand(5));
drawnow
ax = gca;
ax.Units = 'pixels'; %将坐标轴单位更改为像素,以便于确定矩形截取区域。原坐标轴对象起始点为(0,0)
pos = ax.Position
marg = 30;
rect = [-marg,-marg,pos(3)+2*marg,pos(4)+2*marg];
% ti =ax.TightInset; 当涵盖坐标轴即title时,可以精确返回边距
% rect=[-ti(1),-ti(2),pos(3)+ti(1)+ti(3),pos(4)+ti(2)+ti(3)];
F = getframe(gca,rect); %捕获指定矩形区域,返回一个结构体
ax.Units = 'normalized';
figure;
imshow(F.cdata)