matlab says the inline function will be removed in future release how should i execute a string function like '2*x.^2+5'
12 ビュー (過去 30 日間)
古いコメントを表示
function
1 件のコメント
Stephen23
2017 年 6 月 20 日
How about using anonymous functions, just like the documentation recommends?
採用された回答
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.
Alfonso Rodriguez
2021 年 6 月 29 日
Thanks for these comments. They are very useful for computational math.
その他の回答 (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!