How to get WindowButtonMotionFcn to track mouse position

30 ビュー (過去 30 日間)
NICOLA REVELIN
NICOLA REVELIN 2021 年 1 月 9 日
コメント済み: Naum Derzhi 2021 年 6 月 9 日
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.

採用された回答

Mario Malic
Mario Malic 2021 年 1 月 10 日
Here's the question that'll help you, there are more two relevant answers to it. Link
  7 件のコメント
NICOLA REVELIN
NICOLA REVELIN 2021 年 1 月 10 日
Thank you for the help, I've already tried to run and understand that script but the problem is on this line:
set(ax(1).Parent,'windowbuttonmotionfcn', {@mouseMove, ax, gobj});
where the errore says
Error while evaluating Figure WindowButtonMotionFcn.
In a nutshell I cannot set any WindowButtonMotionFcn because when I try to set a callback on the app.Axes the only one available is the ButtonDownFcn
Naum Derzhi
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 ExchangeInteractive Control and Callbacks についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by