MATLAB: Options for displaying data by clicking on a marker in a plot

markerplot

Hello,
is there an option for displaying data in addition to the usual x and y data by clicking on a marker in a plot?
I've plottet the coordinates of broken particles in the xy-plane and I want to display their ID in addition to their respective coordinates. The ID should be disyplayed in the same window as the x and y value (see attachement).

Best Answer

For R2018b and later:
X = rand(10,1);
Y = rand(10,1);
IDs = randi(100,10,1);
s = scatter(X, Y, 'x');
s.DataTipTemplate.DataTipRows(3) = dataTipTextRow('ID', IDs);
For R2018a and earlier, something similar to this:
X = rand(10,1);
Y = rand(10,1);
IDs = randi(100,10,1);
f = figure;
scatter(X, Y, 'x');
dcm = datacursormode(f);
dcm.UpdateFcn = {@customDataTip, IDs};
function txt = customDataTip(~, eventData, IDs)
s = eventData.Target;
pos = eventData.Position;
ID = IDs(s.XData == pos(1) & s.YData == pos(2));
valueFormat = ' \color[rgb]{0 0.6 1}\bf';
removeValueFormat = '\color[rgb]{.25 .25 .25}\rm';
txt = {['X',[valueFormat num2str(pos(1)) removeValueFormat]],...
['Y',[valueFormat num2str(pos(2)) removeValueFormat]],...
['ID',[valueFormat num2str(ID) removeValueFormat]]};
end