waitbar bar inside two for loops

18 ビュー (過去 30 日間)
Alejandro Fernández
Alejandro Fernández 2020 年 8 月 10 日
Hi, I have the folowing code (it's just a example)
maxI = 2;
maxJ = 3;
cont = 1/(maxI*maxJ)
for i = 1:maxI
for j = 1 : max
waitbar(cont,sprintf('Calculating i = %d, j = %d',i,j))
cont = cont + 1/(maxI*maxJ)
pause(rand/10) % here is the code
end
end
If I execute this, every waitbar appears in a new figure, and I want it to just be a figure and automatically update, does someone know?

採用された回答

Geoff Hayes
Geoff Hayes 2020 年 8 月 10 日
Alajendro - rather than creating a new waitbar on each iteration of the inner loop, just create it once and then re-use it. For example,
maxI = 2;
maxJ = 3;
cont = 1/(maxI*maxJ);
hWaitbar = waitbar(0,sprintf('Calculating i = %d, j = %d',0,0)); % create the waitbar
for i = 1:maxI
for j = 1 : maxJ
waitbar(cont, hWaitbar, sprintf('Calculating i = %d, j = %d',i,j)) % update the waitbar
cont = cont + 1/(maxI*maxJ);
pause(rand/10); % here is the code
end
end
We use the bWaitbar handle to update the waitbar with the new progress and new message.
  1 件のコメント
Alejandro Fernández
Alejandro Fernández 2020 年 8 月 10 日
Thank you so much! It works perfectly

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDialog Boxes についてさらに検索

タグ

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by