Detect mouse position over embedded plot in live script.

15 Ansichten (letzte 30 Tage)
DNF
DNF am 20 Mai 2022
Beantwortet: Ravi am 4 Okt. 2023
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?

Antworten (1)

Ravi
Ravi am 4 Okt. 2023
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.

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by