How can I continuously get the mouse coordinates?
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
Walter Roberson
2017-1-29
Note: Callbacks can only return values when the callbacks are used for filtering, such as position constraint "callbacks".
回答(1 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!