MATLAB: How to get the data selected by the user with the datacursor in a Gui

callbackdatacursorguistandalone

I have been tryng to create a gui where a user selects a point in a graph. I want to get the user selection to run another function later. I tried to create a function callback in the points in the graph but did not work. How do I create a callback to the graph points?
Thanks.

Best Answer

An example with a line object, save as file and run exampleGUI:
function exampleGUI
lnH(1) = line(1:12,-1:10, 'lines' ,'none', 'marker' ,'.', 'markers',15,...
'markere','k' , 'buttond',@ln_buttond);
% Additional enlarged marker to highlight selected point
lnH(2) = line(1,-1, 'lines' ,'none', 'marker' ,'o',...
'markere','r' , 'markers',8);
function ln_buttond(varargin)
% Retrieve Xdata and Ydata
XY = get(lnH(1),{'Xdata','Ydata'});
% Get mouse position inside axes
cpaxes = get(gca,'currentpoint');
% Index the click
idx = abs(cpaxes(1) - XY{1}) < 0.25;
% Highligth with bigger marker
set(lnH(2),'Ydata',XY{2}(idx),'Xdata',XY{1}(idx));
end
end
Oleg