Code covered by the BSD License  

Highlights from
Display Cursor Location

5.0

5.0 | 2 ratings Rate this file 21 Downloads (last 30 days) File Size: 2.36 KB File ID: #20892
image thumbnail

Display Cursor Location

by Rodney Thomson

 

29 Jul 2008 (Updated 30 Jul 2008)

Display cursor coordinates within a plot axes window

| Watch this File

File Information
Description

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

MATLAB release MATLAB 7.1.0 (R14SP3)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (3)
01 Jan 2011 Curtis Boodoo

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

12 Apr 2011 Eduardo Gonzalez Rodriguez

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

12 Apr 2011 Rodney Thomson

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.

Please login to add a comment or rating.
Updates
30 Jul 2008

Link to blog entry

Tag Activity for this File
Tag Applied By Date/Time
annotation Rodney Thomson 22 Oct 2008 10:12:16
customization Rodney Thomson 22 Oct 2008 10:12:16
windowbuttonmotionfcn Rodney Thomson 22 Oct 2008 10:12:16
plot Rodney Thomson 22 Oct 2008 10:12:16
display Rodney Thomson 22 Oct 2008 10:12:16
cursor Rodney Thomson 22 Oct 2008 10:12:16
cursor location Rodney Thomson 22 Oct 2008 10:12:16

Contact us at files@mathworks.com