0
votes

I have created a GUI in matlab with a edit box and the user should enter a function so the program may evaluate some values.

However how do I retrieve the function in the textbox and how do I make the proper validations for example if the user enters "sin(coserewrwfc(x))"

My code is:

f = get(handles.funcion,'String'); 
f =inline(f)
f(0)

Thanks for your help

1

1 Answers

1
votes

Here's one way of going about it. Basically it's the same as your code, but in a try/catch block so that if there is an error trying to do f(0), the code will keep running. It will enter the catch statement, where you can manage the error, maybe by displaying a message box asking for the function to be entered again.

try
    f = inline(get(handles.funcion,'String'));
    f(0); %// try something that would fail if the function is defined incorrectly
catch
    disp('There was a problem, please try again')
end