breaking for loop on callback execution
    7 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Vasilisa Iatckova
 el 13 de Dic. de 2021
  
    
    
    
    
    Comentada: Vasilisa Iatckova
 el 6 de Sept. de 2022
            Original question (my own bad-coding-practice-but-super-simple solution below in the accepted answer):
Hello, I have the following code inside of a for loop:
f = figure();
done_button = uicontrol('Parent',f,'Style','pushbutton',...
  'String','Save and quit','Units','normalized','Position',...
  [.915 .92 .07 .03],'Visible','on', 'Callback', @quit);
if done_button.UserData
break
end
and this code for the button callback:
function quit(button, event)
button.UserData = 1;
drawnow
end
The idea is that I want to quit out of the loop when the done button is pressed, but the if statement does not work on button press. I think that's because at the time of the if statement evaluation I have not yet pressed the button, but I don't know how to fix that. I don't want to press this button every loop; only when I want to stop iterating. I looked at this and I'm not sure it applies as I'm not using GUIDE. Would really appreciate help.
4 comentarios
  Voss
      
      
 el 14 de Dic. de 2021
				I would have to see more of your code, particularly the loop the figure and uicontrol are created in. If I have that information, I can probably advise.
Respuesta aceptada
  Vasilisa Iatckova
 el 14 de Dic. de 2021
        
      Editada: Vasilisa Iatckova
 el 14 de Dic. de 2021
  
      
      0 comentarios
Más respuestas (1)
  Walter Roberson
      
      
 el 14 de Dic. de 2021
        f = figure();
done_button = uicontrol('Parent',h,'Style','pushbutton',...
  'String','Save and quit','Units','normalized','Position',...
  [.915 .92 .07 .03],'Visible','on', 'Callback', @quit, ...
  'UserData', 0);
while ~done_button.UserData
  stuff
end
1 comentario
Ver también
Categorías
				Más información sobre Graphics Performance en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


