-
Notifications
You must be signed in to change notification settings - Fork 0
/
perct.m
70 lines (65 loc) · 2.23 KB
/
perct.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
function perct(t,i,n,k)
%PERCT The program procedure.
% PERCT(T,I,N,K) shows the program procedure and remaining time for loops.
% Only K countdowns will be displayed. When the program is completed,
% output the total elapsed time with scale .0000 hours.
%
% t, time elapsed (seconds) recorded by "tic" and "toc"
% i, the number of loops that are completed
% n, the total number of loops
% k, the number of countdowns to be dispalyed, optional
%
% Example:
% k=10;
% tic;
% for i=1:n
% ...
% perct(toc,i,n,k);
% end
%
% Tips:
% 1, you might save the elapsed time by "time=toc/3600" after all loops
% are completed.
% 2, "clc" before calling this function if you only want to see the current
% countdown.
% Jing Wang
% 2014-12-23
% SLIC: a whole brain parcellation toolbox
% Copyright (C) 2016 Jing Wang
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program. If not, see <http://www.gnu.org/licenses/>.
% If k exists, output k countdowns; else, output n countdowns.
if nargin==3 || ( nargin==4 && ismember(i,ceil(n*[1:k]/k)) )
% percentage
fprintf('The program has run: %0.2f%%.\n', i*100/n);
% time remaining
tm=t*(n-i)/i;
% time scale: h, m, s
if tm>60*60
h=floor(tm/(60*60));
m=floor(tm/60-h*60);
fprintf('Remaining time: %d hours %d minutes.',h,m);
elseif tm>60
m=floor(tm/60);
s=floor(tm-m*60);
fprintf('Remaining time: %d minutes %d seconds.',m,s);
elseif tm>0
s=floor(tm);
fprintf('Remaining time: %d seconds.',s);
else % tm=0
h=t/(60*60);
fprintf('Total time elapsed: %0.4f hours.',h);
end
fprintf('\n\n');
end