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!