MATLAB: Matlab GUI axis buttondownfnc Select points

axisbuttondownfcnfigureguipointsselect

I've got a figure with different points that are related in pairs. When clicking in one of the points I would like to change the marker of that point and also the marker of the related point.
Then when clinking in the axis instead of a point return the markers to its original.

Best Answer

Well this sounded like a fun one, so here's what I came up with:
% Set up my data sets. Each pair of x-coordinates goes into one column of a
% 2-by-N array. Each pair of y-coordinates goes into one column of another 2-by-N
% array.
X = [ rand(1,10); rand(1,10) ];
Y = [ rand(1,10); rand(1,10) ];
% Make an axes and plot the lines. When you give PLOT two arrays like this it
% will make a separate line for each column of data.
a = axes;
p = plot(a, X, Y, 'LineStyle', 'none', 'Marker', 'o', 'MarkerSize', 15, 'Color', 'k');
% When you click on the axes, set all of the marker of all the lines.
set(a, 'ButtonDownFcn', @(src, evt) set( p, 'Marker', 'o' ) );
% When you click on a line, set the marker of just the line you clicked on.
set(p, 'ButtonDownFcn', @(src, evt) set( src, 'Marker', 's' ) );