Can the ButtonDownFcn of a plot object identify which point has been clicked?

4 views (last 30 days)
Hi,
Is there a way that I can allow the callback to the clicking into a plot or scatter object to recognize which individual point has been clicked?
I mean, I create a plot as:
h = plot3(1:10,1:10,1:10,'o');
set(h,'ButtonDownFcn','my_callback.m');
Then the callback function accepts the inputs
function my_callback(src,event);
... but inside the body of this function I can only access the handle to the whole plot object (the src argument), which does not seem to contain information on which point was clicked onto to trigger the callback?
Is there a way around this? I know I could just assign a different callback to each point, but for thousands of points (as in my application) the performance slowdown is not acceptable.
Thansk! Daniel

Answers (1)

Image Analyst
Image Analyst on 26 Oct 2012
You can use ginput() to return the x,y coordinate of the point that was clicked. But you have to know that they are going to click and call ginput in preparation for that. If you're just sitting there idle and the user clicks on some image or axes, you may be able to rely on the mousedown event if you set one up. I haven't played around with that for getting x,y coords but it looks like it's possible from the help:
void MouseDown(int16 Button, int16 Shift, Variant x, Variant y)
  1 Comment
Daniel
Daniel on 26 Oct 2012
thanks for the answer, but the problem is that this will not work for 3D data sets (I edited my question to pinpoint that this is the problem).

Sign in to comment.

Categories

Find more on Visual Exploration in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!