Question about mouse click on figure

24 ビュー (過去 30 日間)
mathScience
mathScience 2015 年 2 月 20 日
コメント済み: mathScience 2015 年 2 月 22 日
Hello,
I am trying to put marks on the figure where I click and save it. I used 'ginput'
imshow('image.png')
for i = 1:1000
[p(i,1), p(i,2)] = ginput;
hold on;
plot(p(i,1), p(i,2));
hold off;
end
I found out that 'ginput' is not only taking 'left mouse click,' but also any other mouse clicks or keyboard pressing. Also, I don't know how to undo marking on the figure.
My questions are: Is there any way to only use left mouse click? And, is there any way to undo marking on the figure?
I will appreciate any advice.
Thank you

採用された回答

Mischa Kim
Mischa Kim 2015 年 2 月 20 日
This code snippet should get you started:
button = 1;
getpt = 1;
[x,y,button] = ginput(1);
XY = [x y];
while (getpt == 1)
if (button == 1) % draw line for left mouse click
[xn,yn,button] = ginput(1);
XY = [XY; xn yn];
hold on
plot([x; xn],[y; yn])
x = xn; y = yn;
end
if (button == 3) % clear lines for right mouse click
children = get(gca, 'children');
delete(children);
getpt = 0;
end
end
  1 件のコメント
mathScience
mathScience 2015 年 2 月 22 日
Thank you!

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by