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

4 visualizaciones (últimos 30 días)
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

Respuestas (1)

Image Analyst
Image Analyst el 26 de Oct. de 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 comentario
Daniel
Daniel el 26 de Oct. de 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).

Iniciar sesión para comentar.

Categorías

Más información sobre Specifying Target for Graphics Output en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by