嗨,我想打印一个字符串,同时在最后添加点,而不是每次重复打印字符串之前重新打印字符串.我希望它能够打印,但只将点添加到已打印的字符串中.
reboot = '### rebooting the mmp';
display(reboot)
for i = 1 : 15
reboot = strcat(reboot,'.')
pause(1);
end
Run Code Online (Sandbox Code Playgroud)
我该怎么办?
不是每次都打印出整个字符串,而是每次循环时都可以打印出一个新的点.
为了使这个工作,你将需要使用fprintf打印点,而不是disp因为disp将自动附加一个换行到结尾,fprintf并不会这样所有的点最终在同一行.
% Print the initial message without a trailing newline
fprintf('### rebooting the mmp');
% Print 5 dots all on the same line with a 1-second pause
for k = 1:5
fprintf('.')
pause(1)
end
% We DO want to print a newline after we're all done
fprintf('\n')
Run Code Online (Sandbox Code Playgroud)