首先,您需要計算每次內循環前進時的百分比步長。這可以通過計算來完成:
percent_step = 1.0/n/m/s
然後,你可以強制MATLAB使用\b
(退格字符)的串聯在同一行打印。這裏是一個MWE,只是計算一個隨機10x10矩陣,並得到其轉置(只是爲了顯示進度百分比):
backspaces = '';
percentage = 0;
% DEFINE n, m, s as you wish, here I put some random values
n = 100;
m = 15;
s = 24;
percent_step = 100.0/n/m/s;
for ii = 1:n
for jj = 1:m
for kk = 1:s
% Do stuff
a = rand(10);
b = a';
% Print percentage progress
percentage = percentage + percent_step;
perc_str = sprintf('completed %3.1f', percentage);
fprintf([backspaces, perc_str]);
backspaces = repmat(sprintf('\b'), 1, length(perc_str));
end
end
end
我不是說waitbar。我希望命令窗口中顯示的進度爲打印文本,並根據進度更新文本。 – jingweimo