要以编程方式设置轴边界,有一些有用的命令:
axis([0 30 0 8]); %Sets all four axis bounds
要么
xlim([0 30]); %Sets x axis limits
ylim([0 8]); %Sets y axis limits
要仅设置两个x限制中的一个,我通常使用如下代码:
xlim([0 max(xlim)]); %Leaves upper x limit unchanged, sets lower x limit to 0
这利用了xlims零输入参数调用约定,它返回当前x限制的数组.同样适用于ylim.
请注意,所有这些命令都适用于当前轴,因此如果要创建子图,则需要在构建图时对每个轴执行一次缩放调用.
另一个有用的方法是linkaxes命令.这会动态链接两个图的轴限制,包括像xlim这样的程序化调整大小命令以及平移和缩放等UI操作.例如:
a(1) = subplot(211),plot(rand(10,1), rand(10,1)); %Store axis handles in "a" vector
a(2) = subplot(212),plot(rand(10,1), rand(10,1)): %
linkaxes(a, 'xy');
axis([0 30 0 8]); %Note that all axes are now adjusted together
%Also try some manual zoom, pan operations using the UI buttons.
查看代码,发布编辑后,使用plotmatrix函数会使事情复杂化. plotmatrix似乎创建了自己的轴来工作,因此您需要捕获这些句柄并进行调整. (此外,将来h = zeros(..)退