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.
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!