フィルターのクリア

mouse button click

21 ビュー (過去 30 日間)
tomas
tomas 2011 年 6 月 10 日
回答済み: Conny Fru 2019 年 9 月 25 日
Hello, is it somehow possible to distinguish which mouse button was pressed, left or right?
Thank you

採用された回答

Matt Tearle
Matt Tearle 2011 年 6 月 10 日
The figure has a property 'SelectionType'. This will have the value 'normal' for a left-click, and 'alt' for a right-click.
For more, see the doc: MATLAB -> User's Guide -> HG Property Browser -> Figure -> SelectionType
Example:
function mybttnfcn(h,~)
hf = get(h,'parent');
b = get(hf,'selectiontype');
xy = get(gca,'CurrentPoint');
if strcmpi(b,'normal')
text(xy(1,1),xy(1,2),'Left click')
elseif strcmpi(b,'alt')
text(xy(1,1),xy(1,2),'Right click')
else
text(xy(1,1),xy(1,2),'Careful there, crazy man!')
end
Then try something like:
figure
plot(rand(5))
set(gca,'buttondownfcn',@mybttnfcn)
  2 件のコメント
tomas
tomas 2011 年 6 月 10 日
Thank you, that's what I need.
roudan
roudan 2017 年 11 月 9 日
wow, Matt Tearle, that is really helpful to me. I google it and find your post. Thanks
But I like to change 2D line plot to be 2D point plot and assign a value for each individual point, then extract the value for each point when clicking on the point, how to do that? I don't want to extract XY value. Thanks, I appreciate your help.

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

その他の回答 (2 件)

Sean de Wolski
Sean de Wolski 2011 年 6 月 10 日
Yes. Look at the third output of ginput
doc ginput
  1 件のコメント
tomas
tomas 2011 年 6 月 10 日
Thanks for your answer. I forgot to write that I need to do it in GUI and don't want to use crosshairs. It should be interactive. Is it possible to do it by using buttondownfcn? I want my gui does something after pressing left button and something else after pressing right button.

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


Conny Fru
Conny Fru 2019 年 9 月 25 日
Cheers Matt.

カテゴリ

Help Center および File ExchangeVisual Exploration についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by