File Exchange

image thumbnail

Text progress bar

version 1.0.0.0 (2.16 KB) by Paul
This function creates a TEXT progress bar in your command window.

44 Downloads

Updated 29 Jun 2010

View License

This function creates a text progress bar to show progress of your script in the command window. It should be called with a STRING argument to initialize and terminate. Otherwise the number corresponding to progress in % should be supplied.

INPUTS: Text string to initialize or terminate
Percentage number to show progress
OUTPUTS: N/A

Example: Please see the demo_textprogressbar.m

This function doesn't clear the command window.

Cite As

Paul (2019). Text progress bar (https://www.mathworks.com/matlabcentral/fileexchange/28067-text-progress-bar), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (28)

Yize Wang

Perfect!

Poul Hoang

Xingyu Chen

Great work!

Repurposed this a bit to accept an optional 2nd argument specifying the max value of the iterator. This way the progress bar can always scale to whatever you're looping through, without you having to account for that in your calling function.

If anyone wants the updated src just ping me.

Best,
Spencer

ronaldwheez

ronaldwheez

ronaldwheez

George

most excellent, dude!!

Fritz

Very useful

Easy and fast. Just what I was looking for!

Pot

superb

Kellen

Of course now that I've posted that, the forum doesn't actually allow more than a single space. They DO line up in real life...

Kellen

Works well.
The only improvements I would suggest is the addition of some parameter to make all the progress bars line up:

strSpaceRight = '%-25s';
...
% Progress bar - initialization
c = sprintf(strSpaceRight,c);
fprintf('%s',c);

Doing so allows the user to change the string size by changing the number (currently 25), and has the result of aligning all of the progress bars:

Loading velocity file 100% [..........] Done!
Gridding x/y 100% [..........] Done!
Compute zeta 100% [..........] Done!

I have also added a tab character to the termination to move the termination statement over a little.

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

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-overwritable-message-outputs-to-commandline-window

***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

Eddie

Excellent!

If textprogressbar is initialized in a script ends in an error before textprogressbar is terminated, one must run `clear all` or manually terminate textprogressbar before restarting the script. Otherwise, the persistent variable strCR is not set to [] and the call that would normally initialize textprogressbar instead terminates it. The call to update progress then results in an error.

Nek Valous

Very nice!

Jan

Another nice ASCII progressbar. See also:
http://www.mathworks.com/matlabcentral/fileexchange/23892
http://www.mathworks.com/matlabcentral/fileexchange/21887
http://www.mathworks.com/matlabcentral/fileexchange/19612
http://www.mathworks.com/matlabcentral/fileexchange/16213
http://www.mathworks.com/matlabcentral/fileexchange/15030
http://www.mathworks.com/matlabcentral/fileexchange/11796
http://www.mathworks.com/matlabcentral/fileexchange/8564
http://www.mathworks.com/matlabcentral/fileexchange/8076
http://www.mathworks.com/matlabcentral/fileexchange/6891
http://www.mathworks.com/matlabcentral/fileexchange/6404
http://www.mathworks.com/matlabcentral/fileexchange/4863
Some of them have the remarkable drawback, that they clear the command window - not really helpful, because a progress indicator should *give* information, and not *hide* it.

It would be nice to have the possibility to pause the display of the progress display, print a status message (error or warning) and restart the progress display from the previous point.

Very nice.

Rob Campbell

This is awesome! I've been looking for something like this for ages.

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