从MATLAB显示信息,没有换行 [英] Displaying information from MATLAB without a line feed
问题描述
我的MATLAB程序不时输出一个数字。输出数字之间的程序做了很多其他的东西。这是一个主要用来表示某种进度的结构,每次都不用换行,只是为了让用户更易读。这大概是我要找的:
$ p $ 当前的随机种子
4 7 1 1
程序的下一个输出将在同一行,如果它仍然和以前一样。 p>
我已经阅读了关于disp,sprintf和格式的文档,但没有找到我要找的内容。这并不意味着它不在那里。 ;)
fprintf函数不会添加换行符,除非您明确告诉它。省略fid参数将其打印到命令窗口。
fprintf('Doing stuff ...');
for i = 1:5
fprintf('%d',i);
%在这个过程中做了一些工作...
end
fprintf('done.\\\
'); %\\\
显式地添加了换行符
使用sprintf将不会起作用:它会创建一个字符串没有换行,但是如果你使用disp()或者省略分号,那么disp自己的显示逻辑将会添加一个换行符。
Is there any way to output/display information from a MATLAB program without an ending line feed?
My MATLAB program outputs a number a bit now and then. Between outputting the number the program does a lot of other stuff. This is a construct mainly to indicate some kind of progress and it would be nice not to have a line feed each time, just to make it more readable for the user. This is approximately what I'm looking for:
Current random seed:
4 7 1 1
The next output from the program would be on the same row if it is still doing the same thing as before.
I've read the doc on disp, sprintf, and format but haven't found what I'm looking for. This doesn't mean it isn't there. ;)
The fprintf function does not add a line feed unless you explicitly tell it to. Omit the fid argument to have it print to the Command Window.
fprintf('Doing stuff... ');
for i = 1:5
fprintf('%d ', i);
% do some work on that pass...
end
fprintf(' done.\n'); % That \n explicitly adds the linefeed
Using sprintf won't quite work: it creates a string without a line feed, but then if you use disp() or omit the semicolon, disp's own display logic will add a line feed.
这篇关于从MATLAB显示信息,没有换行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!