How can I continuously get the mouse coordinates?

3 vues (au cours des 30 derniers jours)
Jordan Burnett
Jordan Burnett le 29 Jan 2017
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 commentaire
Walter Roberson
Walter Roberson le 29 Jan 2017
Note: Callbacks can only return values when the callbacks are used for filtering, such as position constraint "callbacks".

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
Walter Roberson le 29 Jan 2017
plot(loc(1,1), loc(1,2), 'r.', 'markersize', 15);

Community Treasure Hunt

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

Start Hunting!

Translated by