How to use GUI for the input of a function? Polynom calculator

2 次查看(过去 30 天)
Dear all,
I worte a function file in Matlab:
Where G is a function and H as well, i is the argument which deicides which mathematical operation should be used.
No im am struggeling a bit. I want to create a gui, which is basically looking like a stanard random calculator, where i can input my G & H Function in the form '2*x^3 -2*x +3'. Then there will be a push buttons for + - * :, I mean the different operations in the gui where I Can chose my i in the function. At the at it should display the new polynom. Cheers, Felix
function POLYNOM( G,H,i)
syms x
if i == 1
Sum = expand(G+H)
elseif i == 2 Difference = expand(G-H) elseif i == 3
Product = expand(G*H)
elseif i == 4
Quotient = expand(G/H) end
end

回答(1 个)

M. A.
M. A. 2017-6-7
编辑:M. A. 2017-6-7
For learning how to build a GUI you could start here: https://mathworks.com/help/matlab/ref/uicontrol.html
For inputting a function like you want to I'd use an Edit-type uicotrol (see link above). Let's say you callled this edit-field myedit:
myedit = uicontrol('Style','edit');
Then you could read the text in there into an anonymous function:
F = eval(['@(x) ' get(myedit,'String')]);
And use this to calculate values:
X = [1 2 3];
Y = F(X);
In your case this should be executed inside the callback functions of your +,-,*,/ pushbuttons.

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by