700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > matlab 判断鼠标按下 Matlab:如何通过使用回调来获取当前鼠标在点击位置

matlab 判断鼠标按下 Matlab:如何通过使用回调来获取当前鼠标在点击位置

时间:2023-01-11 01:20:05

相关推荐

matlab 判断鼠标按下 Matlab:如何通过使用回调来获取当前鼠标在点击位置

I googled near and far, but couldn't get an example of how you associate a callback to the click event in matlab. Can someone show me an example?

解决方案

Define the WindowButtonDownFcn of your figure callback using the set command and an @callbackfunction tag.

Like so:

function mytestfunction()

f=figure;

set(f,'WindowButtonDownFcn',@mytestcallback)

function mytestcallback(hObject,~)

pos=get(hObject,'CurrentPoint');

disp(['You clicked X:',num2str(pos(1)),', Y:',num2str(pos(2))]);

You can also pass extra variables to callback functions using cell notation:

set(f,'WindowsButtonDownFcn',{@mytestcallback,mydata})

If you're working with uicontrol objects, then it's:

set(myuicontrolhandle,'Callback',@mytestcallback)

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。