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

 채택된 답변

Guillaume
Guillaume 2015년 8월 20일

0 개 추천

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.
See the doc for more details.

추가 답변 (1개)

Morteza
Morteza 2015년 8월 20일

0 개 추천

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');

카테고리

도움말 센터File Exchange에서 Function Creation에 대해 자세히 알아보기

질문:

2015년 8월 20일

답변:

2015년 8월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by