Detect mouse position over embedded plot in live script.

13 ビュー (過去 30 日間)
DNF
DNF 2022 年 5 月 20 日
回答済み: Ravi 2023 年 10 月 4 日
I just started using live scripts. Now I am trying to figure out if I can detect mouse position over an embedded plot.
I tried using callback functions and events with the embedded figures, without much luck so far. Here's a non-working example of what I am trying to do:
hfig = figure();
plot(axes('Parent', hfig), rand(5));
hfig.WindowButtonMotionFcn = @(src,evt)disp(src);
This displays a plot inline and I was hoping that when I move the mouse pointer over the plot, the `src` object would be printed out. That does not happen. If I click 'Open in figure window' and then move the mouse over the figure, the callback starts firing.
Is there any way to get callback functions or other events to to work in live scripts. Or is there some other way to read out mouse position in embedded plots?

回答 (1 件)

Ravi
Ravi 2023 年 10 月 4 日
Hi DNF,
According to my understanding, you have a plot on which you want to record the cursor position as your mouse pointer is hovered on the figure.
The figure object has a callback function, “WindowButtonMotionFcn” that triggers when the cursor is hovered on the figure.
Now the objective is to print the position of the cursor every time it is moved. The axes object has a property, “CurrentPoint” that gives the current position of the cursor. The callback function can be written in such a way that the position is printed using the “CurrentPoint” property of the axes object.
For more information, kindly refer to the below links.
Hope this helps.

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by