How to get WindowButtonMotionFcn to track mouse position
30 次查看(过去 30 天)
显示 更早的评论
Hello everyone,
I'm writing a GUI code in wich I basically need to track the position of the mouse in a UIAxes ,and then draw a veritcal line in this position, where some plot are already existing. I've seen in other questions that a WindowButtonMotionFcn could help me to do that but I'm not able to create it. I've also tried with a get(axes_handle,'CurrentPoint') but the problem comes out when I need to point right over a prevoius line for wich no output is given by the "get" function. Could anyone explain me how to get a WindowButtonMotionFcn or at least give me suggestion on how to track mouse position?
Thank you in advance for your help.
0 个评论
采纳的回答
Mario Malic
2021-1-10
Here's the question that'll help you, there are more two relevant answers to it. Link
7 个评论
Naum Derzhi
2021-6-9
WIndowButtonMotion event is generated by the figure, and you need to attach your callback to the figure. You can determine to which figure your axes belongs, checking the object hierarchy. Keep in mind, that axes's parent may be something other than the figure, and you need to move up the object hierarchy until to get to the figure parent (where Type is 'Figure'). In the callback attached to this event you can interrogate all axes children of this window to find out within which axes the cursor was at the time of the event (compare the axes.CurrentPoint to axes limits). Keep in mind, if there are things other than axis in the window, it may happen that the cursor was outside all of them at the time of the event.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!