1

I have the following scatter plot in Matlab:

x = linspace(0,3*pi,200);
y = cos(x) + rand(1,200);  
scatter(x,y)

The user should now be able to click at a circle in the scatter plot. How can I identify at which circle the user has clicked (i.e. at which (x,y) value)?

machinery
  • 5,972
  • 12
  • 67
  • 118

1 Answers1

2

In your callback function, you can use CurrentPoint property of axis object to get (x,y) location:

loc = get(gca, 'CurrentPoint'); % or use dot notation for later Matlab
loc = loc(1, 1:2); % most of the time we are interested in front xy
Xiangrui Li
  • 2,386
  • 2
  • 13
  • 17