MATLAB: Saving mouse click coordinates on image in GUI

gui mouse location

Hello,
How do I record up to 5 mouse click coordinates ([x,y] relative to the image with (0,0) being in the upper left) on an 512 by 512 image (axes1 of my GUI)? I would like the mouse click locations to be saved in a table, so I can use the values for subsequent calculations.
I found the following script online for saving coordinates, but am not sure how it works and where to put this within the GUI script.
function ImageClickCallback (objectHandle , eventData )
axesHandle = get(objectHandle,'Parent');
coordinates = get(handles.axes1,'CurrentPoint');
coordinates = coordinates(1,1:2);
%// then here you can use coordinates as you want ...
For the data-capturing table, I suppose I should be doing the following, but I am not sure which callback section to place it under (do I have to manually create a "mouseclick" callback?):
tableData = {x1,y1,z1;x2,y2,z2;x3,y3,z3;x4,y4,z4;x5,y5,z5};
set(handles.CoordinateTable,'Data',tableData)
The Z values refer to the slice number (obtainable from the slider location) since I am showing a stack of images. I believe that after updating the handles, I should be able to perform my calculations from there.
Apologies for the novice question, as I am quite new to MATLAB. Thank you so much!

Best Answer

You have done well to find that information already. The additional information you need is
to allow you to store the various coordinates.
The ImageClickCallback is something that you would configure as a ButtonDownFcn callback on the image.
You could also consider using ginput(5) to get up to 5 coordinates. The biggest difference between that and using a ButtonDownFcn as a callback is that ginput() is an active command that has to be issued by a running function which would wait for the coordinates and then proceed, whereas callback functions are passive, with no function running until the user triggers the action.
Related Question