how to insert a function into anonymous function

1 vue (au cours des 30 derniers jours)
Ani Asoyan
Ani Asoyan le 31 Jan 2020
Commenté : Star Strider le 31 Jan 2020
I have two functions
function a=f(x,y,z)
y=x.^2+5*y+z
end
and
b = @(x,y,z)(0.6*x+y.^3-z)
I want to insert the first one into the second (anonymous) one. for example
b = @(x,y,z)(0.6*x+y.^3-z+3*a)
how can I do that ?

Réponse acceptée

Star Strider
Star Strider le 31 Jan 2020
Call ‘f’ with the appropriate arguments:
b = @(x,y,z)(0.6*x+y.^3-z+3*f(x,y,z))
Note that ‘a’ is the output, ‘f’ is the function name.
  2 commentaires
Ani Asoyan
Ani Asoyan le 31 Jan 2020
Thank you !
Star Strider
Star Strider le 31 Jan 2020
As always, my pleasure!
This works for single-output functions, because MATLAB always returns the first (or only) ouitput. For multiple-output functions, it would be necessary to evaluate them separately and then use the various outputs in the anonymous function. (They would be passed to the anonymous function as extra arguments.)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Line Plots dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by