How can I interrupt a for or while loop by pressing a button 2?
12 views (last 30 days)
Hi everyone! I have a GUI that populates an excel sheet through a for loop. This for loop I activate through a button 1. However, I am trying to add a button 2 that stops the for loop and that shows a text in the command window through disp () but this button 2 does not work until I lock the loop with Ctrl + C in the command window. Once the loop has been stopped manually and not through the button, the queued messages are seen in the command window. QUESTION: Can someone help me to interrupt the loop through button 2? Thank you very much in advance!
properties (Access = public)
bloqueo = 1;
bloqueo = app.bloqueo;
if bloqueo == 1
PrPres = ;
[rowPrPres, colPrPres] = find(string(raw_actual(:,precioArellenar))==string(ficheroAnterior(l,1)));
PrPres = str2num(ficheroAnterior(l,2));
Rango = strcat(columnaExcelaRellenar,string(rowPrPres(r)));
function PararejecucionButtonPushed(app, event)
app.bloqueo = 0;
Rik on 6 Oct 2021
You can tell Matlab to process callbacks with the drawnow function.
If you put a call to drawnow just before you reload the value of your flag, the callback to the stop button will be processed and the value of the flag set to 0.