File Exchange

image thumbnail

ASCII Progress Bar

version 1.0.0.0 (1.91 KB) by Roy Schestowitz
An ASCII progress bar with timers.

3 Downloads

Updated 25 Apr 2016

View License

This is a relatively powerful ASCII progress bar with indicators of time.
It works under Windows and Linux.

Comments and Ratings (8)

kasim tasdemir

Hi,

I use 'dispstat' function just for this purpose. It can update the previous output which is a missing function of default 'disp'. Very simple to use. It can be downloaded from here:

http://www.mathworks.com/matlabcentral/fileexchange/44673

***Sample usage:
dispstat('','init'); % One time only initialization
dispstat(sprintf('Begining the process...'),'keepthis','timestamp');
for i = 97:100
dispstat(sprintf('Progress %d%%',i),'timestamp');
%doing some heavy stuff here
end
dispstat('Finished.','keepprev');

***Output:
11:25:37 Begining the process...
11:25:37 Progress 100%
Finished.

All the best

code improvement

max=100;
% (1) Set this to the total number of iterations

progress_bar_position = 0;

time_for_this_iteration = 0.01;
% (2) Provide initial time estimate for one iteration

for i=1:max,
tic;


% (3) Place all computations here

pause(0.02)
progress_bar_position = progress_bar_position + 1 / max;
clc;
disp(['|=================================================|']);
progress_string =['|' repmat('#',[1 round(49*(progress_bar_position))])...
repmat(' ',[1 round(49*(1-progress_bar_position))]) '|'] ;

disp(progress_string);
disp(['|================ ',num2str(floor(progress_bar_position * 100),'%0.3u'),...
'% completed =================|']);
% display progress per cent
steps_remaining = max - i;
minutes = floor(time_for_this_iteration * steps_remaining / 60);
seconds = rem(floor(time_for_this_iteration * steps_remaining), 60);
disp(' ');

disp([' Estimated remaining time: ',...
num2str(minutes,'%0.2u'), ':', num2str(seconds,'%0.2u')]);

time_for_this_iteration = toc;
end

W. Th.

Great idea

Oleksandr Zozulya

Note that variable "max" is actually a function in a Matlab, therefore it is strongly advised not to use it.

Hugo Hidalgo

Nice tool. If the following lines are added after the calculation and before the "clc" command, you don't need an initial estimate for completing one iteration. The progess bar will be printed after the first iteration is completed.

if i==1
time_for_this_iteration = toc;
end

Harvey Tobkes

Updates

1.0.0.0

BSD License

MATLAB Release Compatibility
Created with R12
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired: Another ASCII Progress Bar

Discover Live Editor

Create scripts with code, output, and formatted text in a single executable document.


Learn About Live Editor