-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathml_progressBar.m
31 lines (28 loc) · 937 Bytes
/
ml_progressBar.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
function ml_progressBar(k,n, prefixMessage, startT)
% k: current progress
% n: total
%
% See also ml_fprintf, which is even more flexible
% By: Minh Hoai Nguyen ([email protected])
% Created: 24-Mar-2013
% Last modified: 12-Jul-2015
if ~exist('prefixMessage', 'var') || isempty(prefixMessage)
prefixMessage = 'Progress';
end;
nDigit = length(sprintf('%d',n));
if exist('startT', 'var') && ~isempty(startT)
format = sprintf('%%%dd/%d (%%6.2f%%%%), elapse time: %7.1fs', nDigit, n, toc(startT));
delFormat = repmat('\b', 1, 2*nDigit+11+23);
else
format = sprintf('%%%dd/%d (%%6.2f%%%%)', nDigit, n);
delFormat = repmat('\b', 1, 2*nDigit+11);
end
if k==1
fprintf('\n');
fprintf([prefixMessage ' ' format], k, 100*k/n);
elseif k == n
fprintf([delFormat, format, '\n'], k, 100*k/n);
%fprintf(['\n', prefixMessage ' ' format], k, 100);
else
fprintf([delFormat, format], k, 100*k/n);
end;