matlab says the inline function will be removed in future release how should i execute a string function like '2*x.^2+5'

29 次查看(过去 30 天)
function
  1 个评论
Stephen23
Stephen23 2017-6-20
When you read the inline documentation the very first line of text says:
inline will be removed in a future release. Use Anonymous Functions instead.
How about using anonymous functions, just like the documentation recommends?

请先登录,再进行评论。

采纳的回答

Star Strider
Star Strider 2017-6-20
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.
  6 个评论

请先登录,再进行评论。

更多回答(1 个)

Andrei Bobrov
Andrei Bobrov 2017-6-21
syms y
f = matlabFunction(2*y^2+3);

类别

Help CenterFile Exchange 中查找有关 Function Creation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by