2015-05-14 61 views
0

用户给出了一个函数,并且我使用syms(x)ezplot(funcion)作为坐标轴。而在另一种情况下,用户给出的功能和时间间隔为x。在第二个例子中,我使用plot()而不是ezplot()。这里是我的代码=如何在Matlab中填充曲线下的区域

syms x; 

funcion=eval(get(handles.txtFuncion, 'String')); 

ezplot(funcion); 

第二个代码是这样的:

a=eval(get(handles.txtA, 'String')); 

b=eval(get(handles.txtB, 'String')); 

x=a:b; 

funcion=eval(get(handles.txtFuncion, 'String')); 

plot(x,funcion); 
+0

[''区域'](http://www.mathworks.com/help/matlab/ref/area.html)?顺便说一下,根据函数字符串的格式,我建议使用['str2func'](http://www.mathworks.com/help/matlab/ref/str2func.html)和/或['feval'] (http://www.mathworks.com/help/matlab/ref/feval.html)而不是'eval'。 – excaza

+0

我怎样才能使用面积函数,我不知道如何正确使用它 – Telemaco

+0

'a','b'和'funcion'的一些示例字符串是什么? – excaza

回答

2

我没有符号数学工具箱,所以我只能解决第二个代码。

鉴于提供的样本数据:

a = -10; 
b = 10; 
x = a:b; 
h.areaplot = area(x, eval('x.^2')); 

产地:

area plot

编辑:另外,您可以修改你的函数输入语法,而不需要eval工作:

a = str2double(get(handles.txtA, 'String')); 
b = str2double(get(handles.txtB, 'String')); 

x = a:b; 

funcion = str2func(get(handles.txtFuncion, 'String')); 

h.areaplot = area(x, funcion(x)); 

你的文字输入的地方没有w采取的形式'@(x) x.^2'

+0

是的,你需要区域功能。 –