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

4 ビュー (過去 30 日間)
Daniel
Daniel 2012 年 10 月 26 日
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 Center および File ExchangeSpecifying 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