Mouse Down Function doesn't work

2 ビュー (過去 30 日間)
Song Lee
Song Lee 2013 年 10 月 15 日
コメント済み: Song Lee 2013 年 10 月 31 日
I would like to display 'abc' string on command window whenever I click somewhere in a graphic on an axis.
I searched MouseButtonFnc in doc and it says like, "Executes whenever you press a mouse button while the pointer is within the axes, but not over another graphics object."
So, how can I use MouseButtonFnc, clicking somewhere in the picture?
I used imshow function to display a picture on axes1 control.
My code is like this.
I added set(handles.axes1, 'ButtonDownFcn', @axes1_ButtonDownFcn); in Opening Function. And I tried executing "disp('abc')" in axes1_ButtonDownFcn but it didn't work.
Can I please get some advice for this?

採用された回答

Yannick
Yannick 2013 年 10 月 16 日
Hi,
When you are clicking on the picture, you are actually hitting the "image" object created by imshow, and not the axes "axes1" the picture was created in. Try the following two things to see this:
1) Execute the following code:
imshow('board.tif')
figchild = get(gcf,'Children')
get(figchild,'Type')
axchild = get(figchild,'Children')
get(axchild,'Type')
You will see that figchild is an axes, and the child of that axes is an image.
2) In the figure that just opened, go to "View > Property Editor", and click on the picture to give it focus. In the Property Editor pane, you will see that the object in question is of type "image". Another way to see this is by clicking on "More Properties..." and look at the very top of the window that opens up.
So the bottom line is that you are likely clicking on the "image", not "axes1". In fact, a way to see this in your app is to insert the following line where you create your imshow picture:
set(get(handles.axes1,'Children'),'ButtonDownFcn',@(s,e)disp('image clicked!'))
Now, if you click on the picture, it should print "image clicked!" in the Command Window.
Instead of using the axes1 callback, you can either use callbacks associated with the "image" graphics object instead, or you can perhaps use callbacks associated with the "figure" object instead (for example, by using properties such as "WindowButtonDownFcn", "WindowButtonMotionFcn", etc., as well as "CurrentPoint" to determine if you are clicking inside the axes limits or not).
Hope this helps!
  3 件のコメント
Song Lee
Song Lee 2013 年 10 月 17 日
Thank you very much!
Song Lee
Song Lee 2013 年 10 月 31 日
I was swamped with work for several days and finally read your answer carefully. Since my English is not decent, would you please check out whether what I understood is correct or not?
So, an axes on a figure is the child of the figure? and an image on the axes is the child of the axes?
Again, thank you for your kind explanation. That's very educational! :)

サインインしてコメントする。

その他の回答 (1 件)

Jan
Jan 2013 年 10 月 16 日
As Yannick has explained already, the image catches the click event and therefore the axes does not see it anymore. You can eitehr use the ButtonDownFcn of the image, of disable the catching of click events by setting the image's 'HitTest' property to 'off'.
  1 件のコメント
Song Lee
Song Lee 2013 年 10 月 17 日
Thank you! I appreciate it.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by