how to insert a function into anonymous function

4 views (last 30 days)
I have two functions
function a=f(x,y,z)
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 ?

Accepted Answer

Star Strider
Star Strider on 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.
Star Strider
Star Strider on 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.)

Sign in to comment.

More Answers (0)


Find more on Function Creation in Help Center and File Exchange


Community Treasure Hunt

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

Start Hunting!