Question about getpts.m code
3 views (last 30 days)
Show older comments
I was looking at the source code for the function getpts.m, which in 2014a is located in $MATLABROOT\toolbox\images\images\getpts.m.
I understand everything about the function code except lines 33:38. I don't want to paste the source here because the source suggests it's copyrighted. But those lines will cause getpts called in this fashion: getpts(<a string of any MATLAB function>), to execute that function and return from the function. I cannot think of a reason why that piece of code would be there. Is there some meaningful and esoteric reason for the presence of that seemingly useless chunk of code? I would really love to know!
0 Comments
Answers (1)
Guillaume
on 27 Sep 2014
Edited: Guillaume
on 27 Sep 2014
As the comment says (in 2013b), it's to deal with callbacks (that getpts configured).
If you look further down (it's on line 74 in 2013b), getpts sets up callback methods that call getpts with a string. If you look even further down (line 177 onwards), you have functions with the same names as the strings in the callbacks. The whole thing is just to dispatch the callback to those functions.
The reason the callbacks are not set up to call these functions directly is because these functions are only visible from within getpts (since they're defined in that m file and are not the main function).
You could achieve the same thing with anonymous functions, which would have been cleaner, e.g:
set(fig, 'KeyPressFcn', @(o,e) privatefcn);
0 Comments
See Also
Categories
Find more on Introduction to Installation and Licensing 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!