How can I interrupt a for or while loop by pressing a button 2?
15 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Cristian Tacoronte
il 6 Ott 2021
Commentato: Cristian Tacoronte
il 6 Ott 2021
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)
num_anterior
txt_anterior
raw_anterior
num_anterior2
txt_anterior2
raw_anterior2
datos2
nombre2
bloqueo = 1;
end
for l=1:height(ficheroAnterior)
bloqueo = app.bloqueo;
if bloqueo == 1
PrPres = [];
[rowPrPres, colPrPres] = find(string(raw_actual(:,precioArellenar))==string(ficheroAnterior(l,1)));
PrPres = str2num(ficheroAnterior(l,2));
for r=1:length(rowPrPres)
Rango = strcat(columnaExcelaRellenar,string(rowPrPres(r)));
writematrix(PrPres,app.datos2,'Range',Rango);
l
end
else
break
end
end
function PararejecucionButtonPushed(app, event)
app.bloqueo = 0;
disp("paro ejecucion")
end
0 Commenti
Risposta accettata
Rik
il 6 Ott 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.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Startup and Shutdown in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!