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

1 次查看(过去 30 天)
% --- 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);

采纳的回答

Walter Roberson
Walter Roberson 2016-12-4
fun = str2func( ['@(x)' userInput])

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by