MATLAB: In a GUI, How to accept user input and turn string into a function? ex. 3*x^2 +2*x -5

guimatlab guistring to function

% — Executes on button press in Graph.
function Graph_Callback(hObject, eventdata, handles)
syms x y;
userInput = get(handles.user1,'String');
fun = @(x) userInput;
x=0:10;
y = fun(x);
axes(handles.axes1);
plot(x,y);
xlabel('x'); ylabel('y');
guidata(hObject,handles);

Best Answer

fun = str2func( ['@(x)' userInput])
Related Question