添加其他字符串进行打印

时间:2016-10-18 14:50:27

标签: matlab

嗨我会在向最后添加点的同时打印一个字符串,而不是每次重复打印字符串之前重新打印字符串。我希望它能够打印,但只将点添加到已打印的字符串中。

reboot = '### rebooting the mmp';
        display(reboot)

        for i = 1 : 15
            reboot = strcat(reboot,'.')
            pause(1);
        end 

我该怎么做?

2 个答案:

答案 0 :(得分:5)

不是每次都打印出整个字符串,而是每次循环都打印出一个新点。

为了完成这项工作,您需要使用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')

答案 1 :(得分:0)

fprintf(reboot)
for i=1:15
    fprintf('.')
    pause(1)
end
相关问题