Why I got the error "Undefined operator '*' for input arguments of type 'function_handle"?
조회 수: 12 (최근 30일)
이전 댓글 표시
My code:
f=@(x)x+1
g=@(x)x*f+4
g(1)
댓글 수: 0
채택된 답변
Stephen23
2016년 2월 18일
편집: Stephen23
2016년 2월 18일
You need to call the function f, like this:
g=@(x)x*f(x)+4
f is a function handle, not a numeric value. Function handles cannot be multiplied. Only when you call the function handle with its input does it return a numeric value, which can then be multiplied.
This is just like any other function in MATLAB:
5*sin % error, because sin is a function not a value
5*sin(pi) % okay, the function sin returns a numeric value
댓글 수: 1
Dhrumil Patadia
2020년 7월 25일
In this case what would be the difference between x * f(x) and x .* f(x)?
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!