function handle and Subfunction in the command window
조회 수: 3 (최근 30일)
이전 댓글 표시
Hello,
I am working on this quiz question and I don't really understand how this code is working. I have the code attached as an image.
Starting with V2, I see it is myfun2(10,11). I already see that myfun2 is not defined in this folder, so I rule it to be undefined and thus an error.
For V1, start with myfun1(10,11). Then see that V is the LOCAL_myfun2(10,11), with is a+b = 21.
I don't really understand how the H = @LOCAl_myfun2 is working.
Thanks for any clarification of subfunctions and function handles. Also, how does this question depend on whether its run in myfun1.m file, or the command window?
댓글 수: 0
채택된 답변
Henric Rydén
2014년 6월 26일
Hi,
the file myfun1.m contains two functions, one is the main function myfun1 , the other is a local function and can normally not be accessed from outside the main function. To emphasize this, they've named it LOCAL_myfun2 .
Now, they've made it possible to extract LOCAL_myfun2 from myfun1 using the second output from myfun1 . Function handles are simply variables that are functions. After the first command
[V1, myfun2] = myfun1(10,11)
you have one scalar, V1 = 21, and you've also extracted LOCAL_myfun2 in a function handle and named it myfun2 . In the next line, you are using that function and passing 10 and 11 to it, resulting in V2 = 21 .
Hope this helps
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Environment and Settings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!