下面的代码创建了图(2)、图(3)和图(5),但是saveas函数在windows 10中生成一个空文件。我必须第二次运行该代码才能使saveas函数工作?怎么修?
clear; clc;
x=linspace(0,1,5);
x
f=@(x) x.^3
plot(x,f(x),'c'); hold on
figure(2)
saveas(figure(2),'f','emf')
x=linspace(0,1,5);
x
g=@(x) x.^2
plot(x,g(x),'m'); hold on
figure(3)
saveas(figure(3),'g','emf')
x=linspace(0,1,5);
x
f=@(x) x.^3;
g=@(x) x.^2;
plot(x,f(x),'r',x,g(x),'b'); hold on
figure(5)
saveas(figure(5),'fg2.emf')下面的代码类似,第一次成功运行。
x=linspace(0,1,5);
x
f=@(x) x.^3;
plot(x,f(x),'r'); hold on;
figure(4)
g=@(x) x.^2;
plot(x,g(x),'b'); hold off
figure(4)
saveas(figure(4),'fg.emf')我想把f和g画成
plot(x,f(x),'r',x,g(x),'b')为什么会发生这种情况?提前谢谢你。
真的,玛丽
发布于 2017-10-21 05:41:47
您的订单是错误的,让我们举最后一个例子:
%first generate the output you want to plot
x=linspace(0,1,5);
f=@(x) x.^3;
g=@(x) x.^2;
%where do you want to plot it comes first
figure(4)
%and then the plot call
plot(x,f(x),'r');
hold on;
plot(x,g(x),'b');
hold off
%now you can save it
saveas(figure(4),'fg.emf')https://stackoverflow.com/questions/46859409
复制相似问题