我想这就是你需要的。
如果您想要 2 个单独的数字中的上图和下图:
f1 = figure();
count = 1; %Temporary value
axes('Position',[left1 bottom1 width1 height1]);
for i = 1:3:15
subplot(1,5,count);
....code to generate upper figure
count = count+1;
end
f2 = figure();
count = 1; %Temporary value
axes('Position',[left2 bottom2 width2 height2]);
for j = 5:9
subplot(1,5,count);
....code to generate bottom figure
count = count+1;
end
saveas(f1, 'image1.png');
saveas(f2, 'image2.png');
如果你想让上图和下图在同一个图中:
f1 = figure();
count = 1; %Temporary value
axes('Position',[left1 bottom1 width1 height1]);
for i = 1:3:15
subplot(2,5,count);
....code to generate upper figure
count = count+1;
end
count = 6; %Temporary value
axes('Position',[left2 bottom2 width2 height2]);
for j = 5:9
subplot(2,5,count);
....code to generate bottom figure
count = count+1;
end
saveas(f1, 'image.png');
如果一张图中只需要一个上图和下图:
a = 1:3:15;
b = 5:9;
for k = 1:5
f = figure(k);
subplot(2,1,1);
axes('Position',[left1 bottom1 width1 height1]);
i = a(k);
... code to generate upper figure
subplot(2,1,2);
axes('Position',[left2 bottom2 width2 height2]);
j = b(k);
... code to generate bottom figure
print('-dpng','-r800',sprintf('image%d.png',k));
end