Does anyone know how I can get the current position of my cursor when I move over my figure with my cursor?
73 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
This position should be relative to the lower left corner of the figure and the unit should be pixels (to be able to define the position of the axes for example).
How to get the current pointer/mouse position in pixels relative to the lower left corner of the parent container (the red cross should have pixel coordinates [0,0])?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/838860/image.png)
Orange = imread('77.jpg');
figure
imshow(Orange)
0 Kommentare
Antworten (2)
Image Analyst
am 19 Dez. 2021
Use impixelinfo:
Orange = imread('77.jpg');
imshow(Orange)
axis('on', 'image')
impixelinfo
11 Kommentare
Image Analyst
am 6 Jan. 2022
In all the years I've used MATLAB I've never had to mouse around outside an axes and get the (x,y) coordinates. I've only needed the coordinates inside the image itself.
You can get the 'Position' property for all the controls on the figure window, and then dynamically place things. Like if you want a scroll bar halfway between the left of the figure and the left of the axes you can do
pos = handles.axes1.InnerPosition;
pos2 = handles.listbox1.Position;
pos2(1) = pos(1)/2;
handles.listbox1.Position = pos2;
The only thing different than knowing the x value after interactively mousing around and finding it, is line 3 where it's computed relative to other things on the figure window.
Siehe auch
Kategorien
Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!