How can I continuously get the mouse coordinates?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I'm trying to track the position of the mouse as it scrolls across the figure, so I need the coordinates relative to that figure's axes. The best I have so far is this:
% code
function [x, y] = mouseMove(hobject,eventdata)
C = get(gca,'currentpoint');
x = C(1);
y = C(2);
end
axis equal;
axis([-8,8,-7,18]);
hold on;
set(gcf,'WindowButtonMotionFcn',@mouseMove);
while 1
loc = get(gca, 'CurrentPoint');
plot(loc(1), loc(2), 'r.', 'markersize', 15);
pause(.03);
end
However, even this only plots according to the mouse's x position (it plots a straight line, with both the x and y values of that line being equal to the mouse's relative x position). So I'm halfway there, but I'm not sure why the y value is equal to the x value all the time.
1 Kommentar
Walter Roberson
am 29 Jan. 2017
Note: Callbacks can only return values when the callbacks are used for filtering, such as position constraint "callbacks".
Antworten (1)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!