Search code examples
matlabcursorcoordinates

Cursor coordinates in MATLAB figure


I want to find the x and y coordinates of the cursor in a MATLAB figure in real time.

How would I do this in MATLAB?


Solution

  • You should try this:

         values = get (gca, 'CurrentPoint');
         set(gcf,'WindowButtonMotionFcn', @function);
         x = values(1, 1);
         y = values(1, 2);
    

    @function - is name of function, function file name. You can actually call whatever function you want in this case, it can be blank, you still will receive coordinates, also you can write function that returns these values. I found the first way more attractive in my project. It's your choice.