在Python中,我可以将大小传递给figure
指令:
figure(figsize=(8,6))
在Matlab中我没有看到这种能力。我有复杂的建议
set(gcf, 'PaperPositionMode', 'manual');
set(gcf, 'PaperUnits', 'inches');
set(gcf, 'PaperPosition', [2 1 4 2]);
其中包括设置大小和位置。
如何在Matlab中以最简单的方式设置尺寸?
这应该工作:
set(gcf, 'Position', get(gcf,'Position').*[1 1 0 0] + [0 0 newWidth newHeight]);
如果您的MATLAB是R2014b或更新,您还可以:
hF = gcf;
hF.Position(3:4) = [newWidth newHeight];
据我所知,没有可能只设置大小,但你可以获得默认的位置/大小,并将其用作解决方法。要这样做,只需写下:
figPos = get(0,'defaultfigureposition');
width = 400;
height = 400;
figure('Position', [figPos(1), figPos(2), width, height]);
这将仅在初始化图形时设置大小。对于已初始化的数字,请使用图中的handle元素gcf
:
set(gcf, 'Position', [values])
如果要将该大小设置为默认值,请将set
用于属性'defaultfigureposition'
:
set(0, 'defaultfigureposition', [values]);