显示来自 MATLAB 的信息,无需换行
有没有办法在没有结束换行的情况下输出/显示 MATLAB 程序中的信息?
我的 MATLAB 程序时不时地输出一个数字。 在输出数字之间,程序还执行许多其他操作。 这是一个主要用于指示某种进度的构造,最好不要每次都换行,只是为了让用户更容易阅读。 这大约就是我正在寻找的:
Current random seed:
4 7 1 1
如果程序仍然执行与以前相同的操作,则程序的下一个输出将位于同一行。
我已经阅读了有关 disp、sprintf 和 format 的文档,但没有找到我要找的内容。 这并不意味着它不存在。 ;)
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. ;)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
除非您明确指示,否则 fprintf 函数不会添加换行符。 省略 fid 参数以将其打印到命令行窗口。
使用 sprintf 不太有效:它创建一个没有换行符的字符串,但是如果您使用 disp() 或省略分号,disp 自己的显示逻辑将添加换行符。
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.
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.