Matlab:如何通过使用回调来获取当前鼠标在点击位置 [英] Matlab: How to get the current mouse position on a click by using callbacks

查看:986
本文介绍了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?

推荐答案

使用set命令定义图回调的 WindowButtonDownFcn @callbackfunction 标签。

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

像这样:

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})

如果你正在使用uicontrol对象,那么它是:

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

set(myuicontrolhandle,'Callback',@mytestcallback)

这篇关于Matlab:如何通过使用回调来获取当前鼠标在点击位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆