フィルターのクリア

GUI: draw 2 point

3 ビュー (過去 30 日間)
Pinco
Pinco 2012 年 7 月 10 日
Hi everyone!
I'm developing a GUI, and now I have a problem. When I push DRAW button I want to click two times on the image in the figure (loaded before) to drawing two point.
This is my code:
-----
function pushbutton1_Callback(hObject, eventdata, handles)
set(gcf, 'windowbuttondownfcn', @Draw0);
-----
function Draw0(src,evnt)
global x0 y0
pt = get(gca, 'CurrentPoint');
x0 = pt(1, 1);
y0 = pt(1, 2);
hold on
plot(x0,y0,'o','MarkerEdgeColor','k',...
'MarkerFaceColor','r',...
'MarkerSize',8)
----
When I execute my GUI and I press the button I can draw infinity points!! How can I do this? How can I interrupt the function? A function to draw just a point is right too...
Thanks a lot in advance.
Thanks in advance

採用された回答

Matt Kindig
Matt Kindig 2012 年 7 月 10 日
One way to do it is to reset the callback 'windowbuttondownfcn' after two clicks. Something like this:
function pushbutton1_Callback(hObject, eventdata, handles)
global numClicks
numClicks = 0;
set(gcf, 'windowbuttondownfcn', @Draw0);
-----
function Draw0(src,evnt)
global x0 y0 numClicks
pt = get(gca, 'CurrentPoint');
x0 = pt(1, 1);
y0 = pt(1, 2);
numClicks= numClicks+1;
hold on
plot(x0,y0,'o','MarkerEdgeColor','k',...
'MarkerFaceColor','r',...
'MarkerSize',8)
if numClicks > 2,
set(src, 'windowbuttondownfcn', '');
end
  1 件のコメント
Pinco
Pinco 2012 年 7 月 11 日
It works perfectly!!!
Thank you very very very much!!

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by