MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   Matlab:如何通过使用回调获取单击时的当前鼠标位置 (https://www.labfans.com/bbs/showthread.php?t=23386)

poster 2019-12-10 20:41

Matlab:如何通过使用回调获取单击时的当前鼠标位置
 
我在远处用谷歌搜索,但是找不到如何在Matlab中将回调与click事件关联的示例。有人可以给我举个例子吗?



[B]回答:[/B]

定义WindowButtonDownFcn你的身材回调使用set命令和@callbackfunction标签。

像这样:

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))]); 您还可以使用单元格符号将额外的变量传递给回调函数:

set(f,'WindowsButtonDownFcn',{@mytestcallback,mydata}) 如果您正在使用uicontrol对象,则为:

set(myuicontrolhandle,'Callback',@mytestcallback)

[url=https://stackoverflow.com/questions/2769249]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 01:09

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.