MATLAB: Matlab says the inline function will be removed in future release how should i execute a string function like ‘2*x.^2+5’

inline function

function

Best Answer

Your function becomes:
fcn = @(x) 2*x.^2+5;
the call it as you would any other function:
y = fcn(x);
To convert a string to a function, use the str2func (link) function:
str = '2*x.^2+5';
fun = str2func(['@(x) ',str]);
y = fun(x);
This creates the anonymous function from the string, and returns a function handle.
Related Question