Hello,
I am needing to add a progress bar to my code that is basically one 800 line for loop. I keep looking up and trying the basic codes for progress bar already listed on mathworks but I can't seem to figure it out. Can anyone help me figure this out?
Here is the simple one I tried but it doesn't work for me by itself, and I dont know how I would implement it into the for loop either.
function basicwaitbar
f = waitbar(0,'Please wait...');
pause(.5)
waitbar(.33,f,'Loading your data');
pause(1)
waitbar(.67,f,'Processing your data');
pause(1)
waitbar(1,f,'Finishing');
pause(1)
close(f)
end

 採用された回答

Ameer Hamza
Ameer Hamza 2020 年 9 月 24 日

5 投票

See this example
f = waitbar(0, 'Starting');
n = 100;
for i= 1:n
% write your code here
waitbar(i/n, f, sprintf('Progress: %d %%', floor(i/n*100)));
pause(0.1);
end
close(f)

5 件のコメント

Noah Kilps
Noah Kilps 2020 年 9 月 24 日
It says the waitbar has too many input arguments. I am using 2018b if that has anything to do with it.
Ameer Hamza
Ameer Hamza 2020 年 9 月 24 日
Can you show the code which causes the error. R2018b allow the input arguments used in my code.
Noah Kilps
Noah Kilps 2020 年 9 月 24 日
Here is the code that causes the error
Error using waitbar
Too many input arguments.
Error in Driver_Pattern_Feedback_r13 (line 76)
f = waitbar(0, 'Starting');
.
Noah Kilps
Noah Kilps 2020 年 9 月 24 日
I found this code. Using progress bar over waitbar worked better for some reason. See below:
Demos:
% Single bar
m = 500;
progressbar % Init single bar
for i = 1:m
pause(0.01) % Do something important
progressbar(i/m) % Update progress bar
end
Mitsu
Mitsu 2021 年 9 月 21 日
I am using MATLAB 2018b. Ameer's code works as expected.
I suspect Noah's code includes something else that interferred with this minimum working example.
progressbar seems to be a function from MATLAB File Exchange, while waitbar is built in MATLAB.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeApp Building についてさらに検索

質問済み:

2020 年 9 月 24 日

コメント済み:

2021 年 9 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by