Octave:如何防止绘图窗口自行关闭? [英] Octave: How to prevent plot window from closing itself?

查看:127
本文介绍了Octave:如何防止绘图窗口自行关闭?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从八度 CLI 或八度 GUI,如果我运行

plot([1,2,3],[1,4,9])

它将显示一个绘图窗口,我可以查看并与之交互.但是,如果我使用与内容相同的命令创建文件 myPlot.m

plot([1,2,3],[1,4,9])

然后我运行它

octave myPlot.m

然后我可以短暂地看到绘图窗口出现了几分之一秒并立即关闭.如何防止此窗口自行关闭?

八度音程 4.2.2Ubuntu 18.04

解决方案

考虑到评论中的混乱,这里有一个完整的例子.

假设您创建了一个名为 plotWithoutExiting.m 的脚本,旨在直接从 linux shell 调用,而不是从八度音阶解释器中调用:

#!/opt/octave-4.4.1/bin/octaveh = 情节(1:10, 1:10);等待(小时)disp('现在图形对象已被销毁,我可以退出')

linux中的第一行对应'shebang'语法;这个特殊的注释告诉 bash shell 运行哪个解释器来执行下面的脚本.我在这里使用了我的八度可执行文件的位置,你的可能位于其他地方;相应地进行调整.

然后我在 bash shell 中更改权限以使该文件可执行

chmod +x ./plotWithoutExiting.m

然后我可以通过运行它来运行文件:

./plotWithoutExiting.m

或者,您可以跳过 'shebang' 和可执行权限,并尝试通过显式调用 Octave 解释器来运行此文件,例如:

octave ./plotWithoutExiting.m

甚至

octave --eval "plotWithoutExiting"

您还可以添加 --no-gui 选项以防止八度音阶 GUI 弹出.

然后应该运行上面的脚本,将绘图捕获到图形对象句柄 h 中.waitfor(h) 然后暂停程序流程,直到图形对象被销毁(例如通过手动关闭窗口).

理论上,如果你不关心收集图形句柄,你可以使用 waitfor(gcf) 暂停执行,直到最后一个活动图形对象被销毁.

一旦发生这种情况,程序将继续正常运行,直到退出.如果您没有在交互模式下运行 Octave 解释器,这通常也会退出 Octave 环境(如果这不是您想要的,您可以使用 --persist 选项来防止这种情况发生).

希望这会有所帮助.

From the octave CLI or octave GUI, if I run

plot([1,2,3],[1,4,9])

it will display a plot window that I can look at and interact with. If however I create file myPlot.m with the same command as content

plot([1,2,3],[1,4,9])

and that I run it with

octave myPlot.m

then I can briefly see the plot window appear for a fraction of a second and immediatly close itself. How can I prevent this window from closing itself?

Octave 4.2.2 Ubuntu 18.04

解决方案

Here is a full example, given the confusion in the comments.

Suppose you create a script called plotWithoutExiting.m, meant to be invoked directly from the linux shell, rather than from within the octave interpreter:

#!/opt/octave-4.4.1/bin/octave

h = plot(1:10, 1:10);
waitfor(h)
disp('Now that Figure Object has been destroyed I can exit')

The first line in linux corresponds to the 'shebang' syntax; this special comment tells the bash shell which interpreter to run to execute the script below. I have used the location of my octave executable here, yours may be located elsewhere; adapt accordingly.

I then change the permissions in the bash shell to make this file executable

chmod +x ./plotWithoutExiting.m

Then I can run the file by running it:

./plotWithoutExiting.m

Alternatively, you could skip the 'shebang' and executable permissions, and try to run this file by calling the octave interpreter explicitly, e.g.:

octave ./plotWithoutExiting.m

or even

octave --eval "plotWithoutExiting"

You can also add the --no-gui option to prevent the octave GUI momentarily popping up if it does.

The above script should then run, capturing the plot into a figure object handle h. waitfor(h) then pauses program flow, until the figure object is destroyed (e.g. by closing the window manually).

In theory, if you did not care to collect figure handles, you can just use waitfor(gcf) to pause execution until the last active figure object is destroyed.

Once this has happened, the program continues normally until it exits. If you're not running the octave interpreter in interactive mode, this typically also exits the octave environment (you can prevent this by using the --persist option if this is not what you want).

Hope this helps.

这篇关于Octave:如何防止绘图窗口自行关闭?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆