Why does \r (carriage return) also create a new line when printing to the Command Window?
110 次查看(过去 30 天)
显示 更早的评论
MathWorks Support Team
2011-7-13
编辑: MathWorks Support Team
2021-3-3
There does not seem to be a difference in the use of \n or \r. I would like to see the \r only return a carriage return and not a new line as it does in C.
采纳的回答
MathWorks Support Team
2021-3-3
编辑:MathWorks Support Team
2021-3-3
This is a problem when using FPRINTF to print to the screen. FPRINTF will work as expected when writing to a file.
In MATLAB 6.1 (R12.1) it is possible to get the effect you are looking for by using '\b' instead of '\r', where '\b' is the escape character for a single character backspace.
You will need to change the code a little to adjust to the '\b'. Following is an illustrative example:
ix = 1;
chars='|/-\';
fprintf(1,'%c', chars(ix)); % new line
while(1)
fprintf(1,'\b%c', chars(ix)); % modified line
ix = mod(ix,4)+1;
pause(0.05);
end
If multiple spaces need to be deleted, you may use the following code fragment:
for ix=1:numspaces
fprintf('\b')
end
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!