i can write a piece of my code:
appp = uifigure;
appp.Position = [500 500 300 75];
BB = uiprogressdlg(appp,'Message','Calcunate Simulation','Indeterminate','on');
drawnow;
x=1000;
for i=1:x
....
.....
BB.Value = count/n_Loop;
BB.Message = sprintf('Calculate Simulation Equity %d/%d cycle',count,n_Loop);
end
close(BB);
close(appp);
if I want to interrupt the cycle while it is running (with banner running) how can I do it?
Is it possible to add a "Stop" button? and how implement it? (i want to avoid ctrl+c in the editor)

 Akzeptierte Antwort

Voss
Voss am 10 Sep. 2023
Bearbeitet: Voss am 10 Sep. 2023

1 Stimme

Set the uiprogressdlg 'Cancelable' property to 'on' when it is created. Then in the loop, check the 'CancelRequested' property, and break out of the loop if it is true.
appp = uifigure;
appp.Position = [500 500 300 75];
BB = uiprogressdlg(appp,'Message','Calculate Simulation','Indeterminate','on','Cancelable','on');
drawnow;
x=1000;
for i=1:x
if BB.CancelRequested
break
end
% ....
% .....
BB.Value = count/n_Loop;
BB.Message = sprintf('Calculate Simulation Equity %d/%d cycle',count,n_Loop);
end
close(BB);
close(appp);

3 Kommentare

pipor
pipor am 10 Sep. 2023
Bearbeitet: pipor am 10 Sep. 2023
I use "if nested" and I used "return" instead of "break"..it's better
another question: I see to use uiprogressdlg is slows down the loop for me.. is it implemented correctly or is there something faster to know how long it is until the loop exits
Voss
Voss am 10 Sep. 2023
Updating the progress bar takes time; that's what slows down the loop. Instead of updating its Value and Message on each iteration of the loop, you can update every 10 or 100 iterations, which would save some time.
pipor
pipor am 10 Sep. 2023
okk

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 10 Sep. 2023

Kommentiert:

am 10 Sep. 2023

Community Treasure Hunt

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

Start Hunting!

Translated by