Matlab无需单击即可在图像上获取鼠标坐标(在鼠标悬停时) [英] matlab get mouse coordinates on image without clicking (on mouse over)

查看:703
本文介绍了Matlab无需单击即可在图像上获取鼠标坐标(在鼠标悬停时)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜寻了一段时间,以寻找解决这个看似简单的问题的方法:在鼠标移动(无需单击)的同时获取鼠标在图像轴上的坐标.

I've been googling for a while to find a solution to this apparently simple problem: getting mouse coordinates in image axes while the mouse is moving (without clicking).

  1. 我发现impixelinfoval确实做到了这一点,但是我无法从脚本中的uicontrol提取像素坐标(它们存储在某个字段中吗?).

  1. I've found that impixelinfoval does exactly this but I'm not able to extract the pixel coordinates from this uicontrol in the script (are they stored in some field?).

我还发现ginput会给您坐标,但只有在您单击时才能提供坐标.

I've also found that ginput gives you the coordinates but only if you click.

您知道这两个问题之一的任何解决方法吗?

Do you know any workaround for one of these two issues?

您知道使用MATLAB函数完成此操作的任何解决方案吗?

Are you aware of any solution to accomplish this using MATLAB functions?

推荐答案

查看图形窗口的此回调: WindowButtonMotionFcn - http://www.mathworks.com/help/matlab/ref/figure_props.html (您必须向下滚动一个不错的数量,对此感到抱歉)

Check out this callback for the figure window: WindowButtonMotionFcn - http://www.mathworks.com/help/matlab/ref/figure_props.html (you do have to scroll down a decent amount, sorry about that)

每次鼠标移动到图形中的任何位置时,都会触发此功能.从那里,您需要进行调用以获取所需轴的"CurrentPoint".如果当前点在轴范围之内,则说明您的鼠标位于该轴上,并且当前点会告诉您当前点:)

This function will fire every time the mouse moves anywhere within the figure. From there, you need to make a call to get the 'CurrentPoint' of the axis you want. If the currentpoint is within the axis bounds, then you know that your mouse is over the axis and currentpoint tells you, well the current point :)

如果您不在轴上,则ButtonMotionFcn将迅速存在,因此性能不会受到明显影响.

If you are not in the axis, your ButtonMotionFcn will quickly exist and so performance won't be affected noticeably.

这种方法的好处是,您可以将其用于同一功能内的所有轴.

The nice thing about this approach is that you can use it for any axes all within the same function.

这篇关于Matlab无需单击即可在图像上获取鼠标坐标(在鼠标悬停时)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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