필터 지우기
필터 지우기

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