Code covered by the BSD License  

Highlights from
GTRACK

4.83333

4.8 | 7 ratings Rate this file 11 Downloads (last 30 days) File Size: 2.79 KB File ID: #15099

GTRACK

by Jose Pina

 

24 May 2007 (Updated 01 Jun 2007)

Track mouse position and show coordinates in figure title.

Editor's Notes:

This was a File Exchange Pick of the Week

| Watch this File

File Information
Description

GTRACK Track mouse position and show coordinates in figure title.

Once GTRACK is active the mouse position is constantly tracked and printed on the current figure title. A left-click will print the coordinates in the command line and store them. Clicking the mouse right button deactivates GTRACK.

USAGE
gtrack() tracks the mouse and prints coordinates in the command line.

clickData = gtrack() will return the click positions in clickData using UIWAIT. Matlab will be in wait mode until the user finishes clicking.

gtrack('newVar') tracks the mouse and creates a new variable in the base workspace called 'newVar' with the click coordinates. This mode does not use UIWAIT.

gtrack([],titleFormat) uses titleFormat as the format string for printing the mouse coordinates in the title.

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
MATLAB Plot Tracing Utility
This submission has inspired the following:
Mouse Activity Tracking

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 (12)
29 May 2007 John D'Errico

Pretty good. A couple of minor quibbles from me.

The author uses global variables here, where a cleaner coding strategy would be to use nested functions, so there was never any real need for globals.

Next, the code returns its result using assignin, which defines a variable called clickData in the base workspace. Sorry, but this a bit of a kludge, and totally unnecessary. What if there just happens to be a variable with that name in your base workspace? (Perhaps from the last time you used this code.) It gets overwritten. What if you wanted to use this function from within another function? Sorry, but this always writes to the base workspace. Instead, the author could have used uiwait and uiresume to allow the function to return a standard matlab argument.

On the good side, this has an H1 line. It has readable help. It offers attribution to a previous code. It looks for when the cursor exceeds the plot limits. The coding style is reasonable, although I'd have liked to see more internal comments.

30 May 2007 José Pina

Thanks for the suggestions. I hope to submit a new improved entry soon.
I wanted to ask you about the nested function idea. I'm not sure it is possible to use. The point is I'm setting the 'windowbuttonmotionfcn' property of the current figure to 'gtrack(''OnMouseMove'')'. So GTRACK will be called repeatedly by the figure. Between independent calls I'll loose the data. I could alway use persistent instead of global or save the data in the figure handles, but I can't fix it with nested functions. Any suggestion?
Regarding the uiwait, I didn't use it because I wanted to keep the command line active. I know the assignin is dangerous but with the uiwait I might as well just call ginput.
Thanks for the comments once again.

30 May 2007 John D'Errico

This version allows the user to choose how it will return its results. No more globals, nested functions are cleaner. It now has useful internal comments. Well done - my thanks to José.

12 Jul 2007 Tom Pilutti

Beats my own version of this feature that used ginput. I never figured out how to allow user to zoom while function was active. Any possibility for gtrack?

12 Jul 2007 José Pina

Tom,
When you use GTRACK, you loose the toolbar zoom button. But if go to the Tools menu and select zoom in, it does work. Zoom as you wish and then go back to the tools menu to disable zooming and reactivate tracking.

18 Oct 2007 Wendy Luo

Good work. The program is clear and tidy. Thanks Jose.

22 Sep 2008 ShyamSundar Baidya

Thanks for the program.can u help me ?

I want to display some data (left or right) according to the movement of the cursor with respect to current position i.e if the cursor moves left from the current postion i want to display left and same for the right movement.

I thought of storing the value of the previous co-ordinate and compare the X-co ordinate of the current position but i cant store the previous value.Please help me !!

29 Oct 2008 Furi Andi Karnapi

Dear Jose, nice work. Thanks for your acknowledgement.

07 Nov 2008 Tom Richardson

Hi José.
I have the same challenge as ShyamSundar: classifying the movement of the mouse as left/right. However i also wish to record the times that the cursor moved.
Any ideas?
Cheers!

17 Jul 2009 PopV Visitkul

I'm an idiot! Forgot to read the instruction above :-) Nevermind Many thanks again

05 Nov 2010 Conrad  
29 Jul 2011 Anthony Santago

Great piece of software. I'm looking to be able to zoom on a particular location click the mouse then zoom back out and zoom in somewhere else and click the mouse. I commented out the line
"handles.theState = uisuspend(gcf)"
so that I have the capability of zooming but after I zoom I can't get back to being able to click again. Any suggestions?

Please login to add a comment or rating.
Updates
30 May 2007

Improved version (thanks for the hints to John D'Errico)

31 May 2007

Minor documentation correction.

01 Jun 2007

Introduced format string for printing the mouse coordinates in the title.

Tag Activity for this File
Tag Applied By Date/Time
data exploration Jose Pina 22 Oct 2008 09:13:41
graph Jose Pina 22 Oct 2008 09:13:41
mouse track Jose Pina 22 Oct 2008 09:13:41
coordinates Jose Pina 22 Oct 2008 09:13:41
graphical data exploration Jose Pina 22 Oct 2008 09:13:41
graphics Jose Pina 22 Oct 2008 09:13:41
coordinates munqith ali 16 Apr 2009 05:03:29
coordinates Joni Rivilla 08 May 2012 12:35:00

Contact us at files@mathworks.com