Why I got the error "Undefined operator '*' for input arguments of type 'function_handle"?
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Shawn Miller
am 18 Feb. 2016
Kommentiert: Dhrumil Patadia
am 25 Jul. 2020
My code:
f=@(x)x+1
g=@(x)x*f+4
g(1)
0 Kommentare
Akzeptierte Antwort
Stephen23
am 18 Feb. 2016
Bearbeitet: Stephen23
am 18 Feb. 2016
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 Kommentar
Dhrumil Patadia
am 25 Jul. 2020
In this case what would be the difference between x * f(x) and x .* f(x)?
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!