MATLAB: Data Cursor Position in GUI

data cursorguiMATLABmyupdatefcn

I am building a GUI in GUIDE.
The user selects an Image file, which is then displayed in a separate figure/window.
The datacursormode is activated for the figure, and the datatip text is customized.
I want to retrieve the data-cursor's position through the myupdatefcn. I am able to display the position info each time the user clicks somewhere on the image, but I can neither set or setappdata the position for use in another function.
...
imshow(I);
dcm_obj = datacursormode(f);
datacursormode on;
set(dcm_obj,'UpdateFcn', @myupdatefcn )
end
function txt = myupdatefcn(~, event_obj)
pos = event_obj.Position;
disp(['You clicked X:',num2str(pos(1)),', Y:',num2str(pos(2))]);
txt = {'Point to Compute'};
end
How can I retrieve the data cursors' position for use in a separate function in my m file?
p.s. I've tried getCursorInfo(dcm_obj). I haven't been able to get it to work though, even by using a pause or waitforbuttonpress command.
p.p.s. I've read through http://www.mathworks.com/help/techdoc/ref/datacursormode.html. It hasn't helped me much.
Thanks in advance for any help.

Best Answer

Add this line to your myupdatefcn:
set(0,'userdata',pos);
Then from any workspace you can do:
pos = get(0,'userdata');