Effacer les filtres
Effacer les filtres

Why I got the error "Undefined operator '*' for input arguments of type 'function_handle"?

12 vues (au cours des 30 derniers jours)
My code:
f=@(x)x+1
g=@(x)x*f+4
g(1)

Réponse acceptée

Stephen23
Stephen23 le 18 Fév 2016
Modifié(e) : Stephen23 le 18 Fév 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

Plus de réponses (0)

Catégories

En savoir plus sur Multidimensional Arrays dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by