Matlab:保存后消失的图形标签

时间:2014-04-11 12:59:27

标签: matlab matlab-figure figure

我有一个问题,即保存我的数字会使标题消失。

我创建了这个图,看起来像我想要的那样:

subplot(2,1,1);
title('A')
plot(A);
hold on;
plot(B,'rs');
plot(C,'gs');
subplot(2,1,2);
title('D')
plot(D);
hold on;
plot(E,'rs');
plot(F,'gs');

但是为了保存它,我添加了

h= figure
...
saveas(h,namejpg,'jpg');

这样可以节省除标题之外的所有内容。我想保留标题 - 当我定义这个数字时,为什么它们会消失?!任何帮助都非常赞赏。

完整代码如下所示:

h=figure;
subplot(2,1,1);
title('A')
plot(A);
hold on;
plot(B,'rs');
plot(C,'gs');
subplot(2,1,2);
title('D')
plot(D);
hold on;
plot(E,'rs');
plot(F,'gs');
saveas(h,namejpg,'jpg');

1 个答案:

答案 0 :(得分:3)

这是因为标题被添加到子图中,然后在调用plot时清除它。为避免这种情况,只需在调用title后致电plot ,就像这样:

figure
subplot(2,1,1);
plot(A);
title('A')
hold on;
plot(B,'rs');
plot(C,'gs');
subplot(2,1,2);
plot(D);
title('D')
hold on;
plot(E,'rs');
plot(F,'gs');
saveas(h,namejpg,'jpg');