MATLAB: Getting more information from addNewPosi​tionCallba​ck()

addnewpositioncallbackhandleimpointimroi

Hi,
I am using impoint() to drag and drop multiple points on a figure. Whenever a point is moved a function is supposed to be called. (the function stores the coordinates of the point in an array somewhere). addNewPositionCallback() works fine, the function gets called, but I have no way to tell which point has moved – the only inputs the function gets are the point's coordinates. There are several points in the figure at once and I need to know which one has moved. Is there anyway to return a handle to the point, or something similar, using addNewPositionCallback?
Example code or any other help is great 🙂 Thanks!

Best Answer

Major Edit
function playing_with_impoint
imshow('cameraman.tif');
h(1) = impoint;
h(2) = impoint;
addNewPositionCallback(h(1),@mytestcb)
addNewPositionCallback(h(2),@mytestcb)
x(1) = get(h(1),'UIContextMenu');
x(2) = get(h(2),'UIContextMenu');
function mytestcb(pos)
get(gco,'uicontextmenu')==x
end
end
This has to be on the list of cludgiest things I've done but here goes. The IMPOINT and the current object share a 'UIContextMen'. They can thus be linked this way.
Enjoy!