matlab,想让三个子图的大小一样,怎么样设置

matlab画图,我想让三个子图的大小一样,怎么样设置

img


```figure
subplot(3,1,1)
plot(ds,'b','LineWidth',1)
hold on;
plot([a,a],'r--','LineWidth',1.5)
hold on
plot([b,b], 'g--','LineWidth',1.5)
hold on
plot([c,c],'m--','LineWidth',1.5)
hold on
plot([d,d],'c--','LineWidth',1.5)
hold on
plot([e,e], 'k--','LineWidth',1.5)
str1='\fontsize{12}\fontname{宋体}采样点';
xlabel(str1)

lgd = legend('标签1','标签2','标签3','标签4','标签5','标签6','Location','NorthOutside')  % 注意这一行的句尾不加分号;可以显示legend的参数
lgd.NumColumns = 3;
lgd.Location='northoutside';

subplot(312)
plot(ds1,'b','LineWidth',1)
hold on;
plot([a,a],'r--','LineWidth',1.5)
hold on
plot([b,b], 'g--','LineWidth',1.5)
hold on
plot([c,c],'m--','LineWidth',1.5)
hold on
plot([d,d],'c--','LineWidth',1.5)
hold on
plot([e,e], 'k--','LineWidth',1.5)
str1='\fontsize{12}\fontname{宋体}采样点';
xlabel(str1)

subplot(313)
plot(ds2,'b','LineWidth',1)
hold on;
plot([a,a],'r--','LineWidth',1.5)
hold on
plot([b,b], 'g--','LineWidth',1.5)
hold on
plot([c,c],'m--','LineWidth',1.5)
hold on
plot([d,d],'c--','LineWidth',1.5)
hold on
plot([e,e], 'k--','LineWidth',1.5)
str1='\fontsize{12}\fontname{宋体}采样点';
xlabel(str1)


```

该回答引用GPTᴼᴾᴱᴺᴬᴵ
您可以在创建figure对象之后,设置子图的高度和宽度比例,以保证三个子图的大小一致。以下是一个示例代码:

fig = figure;
set(fig, 'Units', 'normalized', 'Position', [0.1, 0.1, 0.8, 0.8]); % 设置整个figure的位置和大小
ax1 = subplot(3,1,1);
plot(ds,'b','LineWidth',1)
%...subplot(1)的绘图代码
ax2 = subplot(3,1,2);
plot(ds1,'b','LineWidth',1)
%...subplot(2)的绘图代码
ax3 = subplot(3,1,3);
plot(ds2,'b','LineWidth',1)
%...subplot(3)的绘图代码
set(ax1,'Position',[0.1 0.67 0.8 0.25]); % 设置第一个子图的位置和大小
set(ax2,'Position',[0.1 0.39 0.8 0.25]); % 设置第二个子图的位置和大小
set(ax3,'Position',[0.1 0.11 0.8 0.25]); % 设置第三个子图的位置和大小


在上述代码中,set函数用于设置子图的属性。其中,'Position'属性设置子图的位置和大小。[0.1 0.67 0.8 0.25]表示子图的左下角坐标为(0.1, 0.67),宽度占整个figure的80%,高度为整个figure的25%。[0.1 0.39 0.8 0.25]和[0.1 0.11 0.8 0.25]分别表示第二个和第三个子图的位置和大小。

设置一下第一个图表的高度。