将图形与子图组合成一个图形

Combine figures with subplots into one figure

在一个集群上做了几次模拟,每次模拟保存一个图,我想把这些图合并成一个图。

为方便起见,假设我们有两个数字:

x = 0:0.01:.2;

subplot(1,3,1)
plot(x,sin(x))
legend('sin(x)')

subplot(1,3,2)
plot(x,cos(x))
legend('cos(x)')

subplot(1,3,3)
plot(x,tan(x))
legend('tan(x)')

x = 0:0.01:.2;

subplot(1,3,1)
plot(x,x,'r')
legend('x')

subplot(1,3,2)
plot(x,1-x.^2/2,'r')
legend('1-x.^2/2')

subplot(1,3,3)
plot(x,x,'r')
legend('x')

另存为 figure1.figfigure2.fig。我现在想将这两个图组合成一个具有 3 个子图、相同颜色和图例的图形。有没有简单的方法可以做到这一点?

从图形菜单文件 -> 生成代码...,您可以生成代码来创建图形。然后你可以根据你的需要修改它(子图索引和位置)与另一个图结合。

我没有找到生成代码的命令。

Open both the figures and copy the objects 一张图到另一张图。

hf1 = openfig('figure1.fig');
hf2 = openfig('figure2.fig');    set(hf2, 'Visible', 'off'); 

for k=1:numel(hf1.Children)
    copyobj(hf2.Children(k).Children, hf1.Children(k));  %Copying objects to figure1
end

所提供示例数据的结果是:


由于提供的示例数据本身,这些图可能太相似而无法被注意到。