MATLAB: How to use the input command to ask the user to enter an equation

inputMATLABvariable

I want to write a command which will allow the user to enter an equation in terms of x and also, ask the user to enter the value of the variable x.

Best Answer

See this example
str = 'sin(x)*exp(x)'; % input function in term of x
f = str2func(['@(x)' str]); % convert to MATLAB function
x = 2; % evaluate at x=2
f(2) % evaluate the function
Related Question