필터 지우기
필터 지우기

how to define a function inside a function?

조회 수: 2 (최근 30일)
Nadia Bica
Nadia Bica 2015년 4월 8일
댓글: Nadia Bica 2015년 4월 8일
hello i hava defined a function:
function jj= jj1(C1, C2, C3, C4, k, q, P,gg, x) jj = C1*cos(k*x)+C2*sin(k*x)+C3*x+C4+gg
the thing is that gg is also a function:
gg1=gg(q,P,x) gg1=q/(2*P)*x^2
obviously this is most likely to be wrong because I have no idea how to do it. Can anyone give me some help please. i put the editor as attachemnent.
  댓글 수: 1
Stephen23
Stephen23 2015년 4월 8일
편집: Stephen23 2015년 4월 8일
Please edit your question and do both of these things:
  • Format your code correctly using the {} Code button that you will find above the text box.
  • Attach the file by clicking both buttons: Choose File and Attach file (otherwise it does not upload).

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

채택된 답변

Titus Edelhofer
Titus Edelhofer 2015년 4월 8일
Hi,
if gg is a function you will need to create it and pass to jj1. You can e.g. create an anonymous function:
gg = @(q,P,x) q./(2*P)*x.^2;
% now call jj1:
result = jj1(C1, C2, C3, C4, k, q, P, gg, x);
% and inside jj1:
gg1 = gg(q, P, x);
or you create a seperate .m file:
function gg1 = gg(q, P, x)
gg1 = gg(q, P, x);
and now pass the function handle to jj1:
result = jj1(C1, C2, C3, C4, k, q, P, @gg, x);
Titus

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by