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 个评论
采纳的回答
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);
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 个评论
Steven Lord
2017-6-21
Use the symvar function to identify the variable(s) and use the char vector it returns in defining the char vector you pass into str2func.
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Function Creation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!