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

### Felix_2991 (view profile)

on 26 May 2017
Latest activity Edited by M. A.

### M. A. (view profile)

on 7 Jun 2017
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

on 7 Jun 2017
Edited by M. A.

### M. A. (view profile)

on 7 Jun 2017

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.