how to insert a function into anonymous function

조회 수: 1 (최근 30일)
Ani Asoyan
Ani Asoyan 2020년 1월 31일
댓글: Star Strider 2020년 1월 31일
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 ?

채택된 답변

Star Strider
Star Strider 2020년 1월 31일
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
Ani Asoyan
Ani Asoyan 2020년 1월 31일
Thank you !
Star Strider
Star Strider 2020년 1월 31일
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.)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by