Capturing Mouse click on a Figure

Hi to All,
I am building a simple code that should detect the left mouse button when it is clicked on a figure. When the click is captured, a variable (e.g: y) should change its value from 0 to 1.
Th is is my code, in which I check on WindowButtonDown to invoke sendout function. sendout function shall set UserData to 1, in which I pass it to y. I run the code and I got ans = []!
Does anyone have an idea about mouse clicking in Matlab?!
Many thanks. Mahmood %% The code function y=main2
f=figure;
set(f,'WindowButtonDown',{@sendout});
function sendout(varargin)
set(f,'UserData',1);
end
y =get(f,'UserData');
end

 採用された回答

Thomas
Thomas 2012 年 5 月 8 日

0 投票

Dunno if this will help
y=0 % intial value of y==0
k=waitforbuttonpress; % detect mouse click
if k==0 % on detect make y=1
y=1
end

1 件のコメント

Mahmood
Mahmood 2012 年 5 月 9 日
Oh yea!
Thanks for the solution. That is more easier and efficient

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeGraphics Object Properties についてさらに検索

タグ

質問済み:

2012 年 5 月 8 日

Community Treasure Hunt

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

Start Hunting!

Translated by