Plotting a concatenated function (GUI)

1 回表示 (過去 30 日間)
Susan G
Susan G 2019 年 6 月 20 日
編集済み: Stephan 2019 年 6 月 21 日
I have created a GUI interface that allows a user to enter three different values (a, b, c) which are coefficients for a quadratic equation. I am trying to then plot the quadratic equation on axes1 in the GUI interface.
testa=(get(handles.a,'String'));
testb=(get(handles.b,'String'));
testc=(get(handles.c,'String'));
testfun=strcat(testa,'.*x.^2+',testb,'.*x+',testc);
x=-5:.5:5;
axes(handles.axes1)
plot(x,testfun)
I get the following error:
Error using plot
Error in color/linetype argument.
I know what the error is. Passing testfun as a string to plot doesn't work. I've tested the following through the command line:
x=-5:.5:5
funy1=1.*x.^2+5*x+6
funy2='1.*x.^2+5*x+6'
plot(x,funy1) worked and plot(x,funy2) did not work.
So....my question is if I have to concatenate inputs from the GUI (a,b,c) with the '.*x.^2+' and '.*x+" to get my equation to graph, how can I make it without the single quotes (i.e. not a string) so I can plot the equation that I created through the concatenation process?
Thanks for your time and feedback!

採用された回答

Stephan
Stephan 2019 年 6 月 21 日
編集済み: Stephan 2019 年 6 月 21 日
x=-5:.5:5
funy2=str2func('1.*x.^2+5*x+6')
plot(x,funy2(x))

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by