matlab saveas函数导致空图

时间:2017-10-21 02:09:46

标签: matlab graph

下面的代码创建了图(2),图(3)和图(5),但是saveas函数导致了Windows 10中的空文件。我必须再次运行代码才能使saveas函数工作?怎么解决?

Information:java: The system is out of resources. 
Information:java: Consult the following stack trace for details.
Information:java:   at com.sun.tools.javac.code.Type.map(Type.java:220)
Information:java: Errors occurred while compiling module 'SearchAlgo'
Information:javac 1.8.0_144 was used to compile java sources
Information:21/10/17, 12:02 PM - Compilation completed with 1 error and 0 warnings in 1s 481ms 
Error:java: java.lang.StackOverflowError

以下代码类似,并且第一次成功运行。

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')

我想用

绘制f和g
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')

为什么会这样?提前谢谢。

真诚的,玛丽

1 个答案:

答案 0 :(得分:0)

您的订单有误,让我们举一个例子:

%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')