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 CenterFile Exchange 中查找有关 Annotations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by