Cursor position over an image in MATLAB

332 views Asked by At

I have an image opened in an axes object inside a GUIDE MATLAB GUI. I want to be able to update some variables depending in the position of the cursor over the image. My effort in order to achieve it has been to use the following code to set the behavior of the axes:

pointerBehavior.enterFcn    = [];
pointerBehavior.exitFcn     = [];
pointerBehavior.traverseFcn = @(figHandle, currentPoint)CoordChanger(figHandle,currentPoint, hObject, handles); 
iptSetPointerBehavior(handles.axes1, pointerBehavior);
iptPointerManager(gcf);

With the following function:

function CoordChanger(figh, cp, hObject, handles)
handles.output = hObject;

    CursorPosition = get(handles.axes1,'CurrentPoint')

guidata(hObject, handles);

However when I look at the CursorPosition value while I’m moving the cursor along the image it always shows the same value. What am I doing wrong? Is there any other way to achieve the same result?

1

There are 1 answers

0
Tokkot On

Look at the cp variable inside CoordChanger, you should see the cursor position changing there.