how to use function handle
1 次查看(过去 30 天)
显示 更早的评论
I have a function boop:
function boop(A)
disp(A)
Now I want that whenever I move my mouse over a figure, the function will display 'hello world', How do i have to set the function? :
set(gcf,'windowButtonMotionFcn',@boop)
set(gcf,'windowButtonMotionFcn',@('hello world')boop)
set(gcf,'windowButtonMotionFcn',@boop('hello world'))
set(gcf,'windowButtonMotionFcn',@boop,('hello world'))
None of the above is working.
Thanks
0 个评论
采纳的回答
Guillaume
2015-8-20
This should work:
set(gcf, 'windowButtonMotionFcn', @(~, ~) boop('hello world'));
A UI callback always receives two arguments (an object handle and some event data), which you need to accept. I've done that above by creating an anonymous function that accepts and ignores these two arguments (the @(~, ~)) and then simply call your handle with the correct argument.
0 个评论
更多回答(1 个)
Morteza
2015-8-20
if you are using the GUI of Matlab in the figure-Ispector find the WindowsButtonMotionFcn and create its function then pregame it like as you want. like bellow:
function figure1_WindowButtonMotionFcn(hObject, eventdata, handles)
warndlg('hello','rrr');
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Scope Variables and Generate Names 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!