我遇到一个问题,保存我的图形会使标题消失。
我创建了这个图形,它看起来像我想要的那样:
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');
最佳答案
发生这种情况是因为标题被添加到子图中,然后在调用 plot
时被清除。为了避免这种情况,只需在调用 plot
之后调用 title
即可,如下所示:
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');
关于Matlab:保存时图形标签消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23013292/