如何刷新 Matlab 或 Octave 中 disp 的输出?

发布于 2024-08-28 13:45:43 字数 339 浏览 5 评论 0原文

我在 Octave 中有一个程序,它有一个循环 - 运行一个带有各种参数的函数,而不是我可以转换成矩阵的东西。在每次迭代开始时,我使用 disp 打印当前参数。

我第一次运行它时,我得到了巴西警告,然后我也得到了这些照片。现在我把它们清理干净了,我就再也看不到它们了。我的猜测是它们被困在缓冲区中,当程序结束或缓冲区填满时我会看到它们。

有什么方法可以强制刷新打印缓冲区以便我可以看到我的打印结果吗?

I have a program in Octave that has a loop - running a function with various parameters, not something that I can turn into matrices. At the beginning of each iteration I print the current parameters using disp.

The first times I ran it I had a brazillion warnings, and then I also got these prints. Now that I cleaned them up, I no longer see them. My guess is that they're stuck in a buffer, and I'll see them when the program ends or the buffer fills.

Is there any way to force a flush of the print buffer so that I can see my prints?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

你穿错了嫁妆 2024-09-04 13:45:43

使用 fflush(stdout) 和/或 fflush(stderr) 从 disp() 刷新缓冲区。

Use fflush(stdout) and/or fflush(stderr) to flush the buffer from disp().

柠北森屋 2024-09-04 13:45:43

正如 moastab 所提到的,fflush(stdout) 适用于 Octave。

在 MATLAB 中,使用 drawnow('update') 刷新输出。

MATLAB 的 drawnow 函数对于在 MATLAB 中控制图形对象重绘的人员来说很熟悉,但它也适用于 stdout stderr 缓冲区。 'update' 选项不是必需的,但会将刷新限制为非图形队列。此详细信息仅隐含在drawnow() 文档中;我已经验证它可以在循环中处理 fprintf 调用。

As mentioned by moastab, fflush(stdout) works for Octave.

In MATLAB, use drawnow('update') to flush the output.

MATLAB's drawnow function will be familiar to those who control the redrawing of graphical objects in MATLAB, but it applies to the stdout stderr buffers as well. The 'update' option is not required, but limits the flushing to non-graphical queues. This detail is merely implied in the drawnow() documentation; I have verified it to work on fprintf calls in a loop.

败给现实 2024-09-04 13:45:43

Octave:您可以通过调用more off来关闭输出缓冲。

这将禁用分页,以便所有输出都直接发送到屏幕。

Octave: You can turn off buffering of output by calling more off.

This will disable pagination such that all output is sent directly to the screen.

°如果伤别离去 2024-09-04 13:45:43

将以下命令放在您的部分或代码的开头:

page_screen_output(0);

page_output_immediately(1);

Put the following commands at the beginning of your section or your code:

page_screen_output(0);

page_output_immediately(1);
夏日浅笑〃 2024-09-04 13:45:43

如果我正确理解您的问题,您可以使用 diary 函数将所有会话输出转储到文本文件。 diary on 将开始录制,diary off 将停止。 diary filename 将使用文件名而不是默认的“diary”。

它是 Octave 和 MATLAB 中的内置函数。有关更多详细信息,请参阅帮助日记


您还可以增加 Octave 缓冲区大小。在 Windows 上,您可以在左上角菜单的“八度属性”对话框中执行此操作。

If I understand your question correctly, you can use diary function to dump all session output to a text file. diary on will start recording, and diary off will stop. diary filename will use filename instead of default "diary".

It is build -in function in both Octave and MATLAB. For more details see help diary.


Also you can increase Octave buffer size. On Windows you can do it in Octave Properties dialog from upper left corner menu.

凡间太子 2024-09-04 13:45:43

这里和其他地方,有至少有 5 种方法可以立即输出,以 Octave 为单位。

使用以下之一

%---------------------------
% Turn OFF output buffering
%---------------------------
more off                        % command & NOT shown in output
PAGER = "less"                  % built-in var - shown in output
page_screen_output = 0          % built-in var - shown in output
page_output_immediately = 1     % built-in var - shown in output
fflush(stdout)                  % Need to call after each "output" line

From here and elsewhere, there are at least 5 methods to get immediate output, in Octave.

Use one of the following:

%---------------------------
% Turn OFF output buffering
%---------------------------
more off                        % command & NOT shown in output
PAGER = "less"                  % built-in var - shown in output
page_screen_output = 0          % built-in var - shown in output
page_output_immediately = 1     % built-in var - shown in output
fflush(stdout)                  % Need to call after each "output" line
地狱即天堂 2024-09-04 13:45:43

drawnow 将导致图形更新,我不确定它是否也适用于 stdout 管道。

您还可以将 disp(...) 语句转换为 fprintf(stderr, ...),我认为 stderr 的处理方式与Octave 上的stdout

drawnow will cause graphs to update, I'm not sure if it works on the stdout pipe as well.

You might also convert your disp(...) statements to fprintf(stderr, ...), I think stderr is handled differently from stdout on Octave.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文