Effacer les filtres
Effacer les filtres

GUI: draw 2 point

3 vues (au cours des 30 derniers jours)
Pinco
Pinco le 10 Juil 2012
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

Réponse acceptée

Matt Kindig
Matt Kindig le 10 Juil 2012
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 commentaire
Pinco
Pinco le 11 Juil 2012
It works perfectly!!!
Thank you very very very much!!

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by