如何使用 MATLAB 从 gui 获取参数来绘制抛物线
How to plot a parabola by getting its parameters from the gui using MATLAB
我试过这样做:
我找到了这个 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
,但在yToPlot
中使用了变量x
。这就是为什么您会收到一条错误消息,指出 x
未定义。同样在 yToPlot
中你有 b.x
。然后 MATLAB 认为 b
是一个结构,并且您想访问 b
的名为 x
的字段。由于 b
不是结构,并且没有字段 x
,您将收到错误 'Attempt to reference field of non-structure array.'。如果你修复了这两个,它应该可以工作,根据你给出的代码:
xLine=[(-b)/2*a-5:0.01:(-b)/2*a+5];
yToPlot= a*xLine.^2 + b*xLine+c;
plot(xLine,yToPlot);
我试过这样做:
我找到了这个 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
,但在yToPlot
中使用了变量x
。这就是为什么您会收到一条错误消息,指出 x
未定义。同样在 yToPlot
中你有 b.x
。然后 MATLAB 认为 b
是一个结构,并且您想访问 b
的名为 x
的字段。由于 b
不是结构,并且没有字段 x
,您将收到错误 'Attempt to reference field of non-structure array.'。如果你修复了这两个,它应该可以工作,根据你给出的代码:
xLine=[(-b)/2*a-5:0.01:(-b)/2*a+5];
yToPlot= a*xLine.^2 + b*xLine+c;
plot(xLine,yToPlot);