你可以使用linkaxes函数:
figure
ax1 = subplot(2,2,1);
x1 = linspace(0,6);
y1 = sin(x1);
plot(x1,y1)
ax2 = subplot(2,2,2);
x2 = linspace(0,10);
y2 = sin(2*x2);
plot(x2,y2)
ax3 = subplot(2,2,[3,4]);
x3 = linspace(0,16);
y3 = sin(6*x3);
plot(x3,y3)
linkaxes([ax1,ax2,ax3],'x')
用法:
linkaxes(ax) 链接指定的Axes 对象的 x 轴和 y 轴范围
在矢量ax 中。 linkaxes 函数选择包含
所有链接轴的当前限制。
linkaxes(ax, option)根据指定的option链接坐标轴ax。
option 参数可以是以下值之一:
'x' 仅链接 x 轴。
'y' 仅链接 y 轴。
'xy' 链接 x 轴和 y 轴。
'off' 删除链接。
参考这里:https://www.mathworks.com/help/matlab/ref/linkaxes.html
如果您的 matlab 早于 2006 年,您可以按照以下步骤操作:https://www.mathworks.com/matlabcentral/fileexchange/7169-samexaxis-nice-subplots-with-same-x-axis