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

4 次查看(过去 30 天)
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

回答(1 个)

Image Analyst
Image Analyst 2012-10-26
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 个评论
Daniel
Daniel 2012-10-26
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).

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by