GUI: draw 2 point
2 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!