File Exchange

image thumbnail

Display Cursor Location

version 1.0 (2.36 KB) by

Display cursor coordinates within a plot axes window

8 Downloads

Updated

View License

Display the current cursor coordinates within the bounds of a plot axes.

Assigned as a WindowButtonMotionFcn callback function. Only updates when mouse is moved over plot contents.

To use (See screenshot):

t = linspace(-5,5);
y = sinc(t);
f = figure;
plot(t, y, 'r');

set(f, 'WindowButtonMotionFcn', @(obj, event)cursorLocation(obj, event, 'BottomLeft', ' X: %.3f\n Y: %.3f', 'r'))

For more information:
http://iheartmatlab.blogspot.com/2008/07/display-cursor-coordinates.html

Comments and Ratings (4)

Leslie

Leslie (view profile)

works fine
Thanks

Rodney Thomson

Rodney Thomson (view profile)

Eduardo, for a simple hack you could replace 'WindowButtonMotionFcn' in the above example with 'WindowButtonDownFcn' and it will respond to button clicks (both left and right) but only when not in zoom/pan mode.

Great function. Is there any way to use it to get the position when the mouse left button is clicked over the image? as in ginput function, to capture several cursor positions. thanks

Diablo

Diablo (view profile)

Thank you so much for your submission it really helps with my analysis of my plots!. Keep up on the great work!!!

MATLAB Release
MATLAB 7.1.0 (R14SP3)
Acknowledgements

Inspired: stackobj, dtmcursor

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video