首先,您需要计算每次内循环前进时的百分比步长。这可以通过计算来完成:
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