如何使用MATLAB从gui获取参数来绘制抛物线

问题描述 投票:-1回答:1

我试过这样做:

我发现这个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);

但我一直在收到错误...任何帮助将不胜感激

matlab plot matlab-guide
1个回答
0
投票

您定义变量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);
© www.soinside.com 2019 - 2024. All rights reserved.