按照 Yair 和 Amro 的建议,使用 linkaxes。以下是您的案例的一个简单示例
ha(1) = subplot(2,1,1); % get the axes handle when you create the subplot
plot([1:10]); % Plot random stuff here as an example
ha(2) = subplot(2,1,2); % get the axes handle when you create the subplot
plot([1:10]+10); % Plot random stuff here as an example
linkaxes(ha, 'x'); % Link all axes in x
您应该能够同时放大所有子图
如果有很多子图,并且一个一个地收集它们的坐标轴句柄似乎不是一个聪明的方法来完成这项工作,您可以通过以下命令找到给定图形句柄中的所有坐标轴句柄
figure_handle = figure;
subplot(2,1,1);
plot([1:10]);
subplot(2,1,2);
plot([1:10]+10);
% find all axes handle of type 'axes' and empty tag
all_ha = findobj( figure_handle, 'type', 'axes', 'tag', '' );
linkaxes( all_ha, 'x' );
第一行查找figure_handle 下类型为“axes”和空标记('')的所有对象。空标签的条件是排除图例的斧头句柄,其标签将为legend。
如果它不仅仅是一个简单的绘图,您的图中可能还有其他轴对象。在这种情况下,您需要添加更多条件来识别您感兴趣的绘图的轴句柄。