我试过这样做:
我发现这个https://www.quora.com/How-do-I-draw-a-parabola-in-MATLAB并尝试使用它:
a=str2double(get(handles.InputA,'string'));
b=str2double(get(handles.InputB,'string'));
c=str2double(get(handles.InputC,'string'));
xLine=[(-b)/2*a-5:0.01:(-b)/2*a+5];
yToPlot= a*x.^2 + b.x+c;
plot(xLine,yToPlot);
但我一直在收到错误...任何帮助将不胜感激
您定义变量xLine
,但在x
中使用变量yToPlot
。这就是为什么你得到一个错误,说x
没有定义。同样在yToPlot
你有b.x
。 MATLAB然后认为b
是一个结构,你想访问x
的名为b
的字段。由于b
不是结构,并且没有字段x
,因此您将获得错误“尝试引用非结构数组的字段”。如果你修复这两个,它应该工作,根据你给出的代码:
xLine=[(-b)/2*a-5:0.01:(-b)/2*a+5];
yToPlot= a*xLine.^2 + b*xLine+c;
plot(xLine,yToPlot);