从命令行调用函数时绘制八度音程

发布于 2024-11-26 16:50:55 字数 305 浏览 2 评论 0原文

我正在尝试从命令行运行octave 中的函数。该函数当前的运行方式如下:

octave --silent --persist --eval 'function(input arguments)'

function.m contains a plot命令。当我使用上述命令行参数调用 Octave 时,绘图确实显示,但 Octave 进入交互模式。我的问题是:

有没有办法让八度音阶显示绘图而无需从命令行调用时进入交互模式?

I am trying to run a function in octave from the command line. The function is currently run like so:

octave --silent --persist --eval 'function(input arguments)'

function.m contains a plot command. When I invoke octave with the above command line parameters, the plot does show but octave enters into its interactive mode. My question is:

Is there any way to get octave to display the plot without entering the interactive mode when it is invoked from the command line?

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

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

发布评论

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

评论(6

杀手六號 2024-12-03 16:50:55

只需在绘图函数之后使用 pause

Just use pause after your plotting functions

南冥有猫 2024-12-03 16:50:55

你可以在最后使用:

waitfor(h)

,等待你关闭该图。

You can use:

waitfor(h)

at the end, which waits for you to close the figure.

嘦怹 2024-12-03 16:50:55

AFAIK,绘图窗口是八度的子进程,因此只能在八度运行时显示。即使您在“交互”模式下绘制某些内容,让绘图保持打开状态并关闭八度音程,绘图也会消失。
您可以做的就是绘制一些输出文件,如此处发布:

f = figure
set(f, "visible", "off")
plot([1,2,3,4])
print("MyPNG.png", "-dpng")

AFAIK, the plot window is a child process of octave and therefor can only be displayed when octave is running. Even if you plot something from the "interactive" mode leave the plot open and close octave, the plot will also disappear.
What you could do is to plot to some output file like posted here:

f = figure
set(f, "visible", "off")
plot([1,2,3,4])
print("MyPNG.png", "-dpng")
标点 2024-12-03 16:50:55

您需要选择合适的图形工具包:

available_graphics_toolkits 
ans = 
{
  [1,1] = fltk
  [1,2] = gnuplot
}

默认为fltk,它无法在不显示绘图的情况下写入文件。但是,如果您选择 gnuplot,它将能够写入文件而不先显示它。在您的文件中以以下内容开头:

graphics_toolkit gnuplot

You need to select a proper graphics toolkit:

available_graphics_toolkits 
ans = 
{
  [1,1] = fltk
  [1,2] = gnuplot
}

The default is fltk which cannot write to file without displaying the plot. However, if you select gnuplot it will be able to write to file without displaying it first. In your file start with:

graphics_toolkit gnuplot
ヅ她的身影、若隐若现 2024-12-03 16:50:55

问题是,当您从命令行运行时,当它结束时,绘图窗口随之消失。

#! /usr/bin/octave -qf
f = figure;
set(f, "visible", "off")

t=0:0.001:5*pi;
plot(t, sin(5*t)), grid

print("MyPNG.png", "-dpng")

这会将输出保存到运行目录中的 MyPNG.png。

然后你可以用可视化程序打开它。

添加

pause

另一种选择是在程序末尾

,以便等待用户输入终止,从而关闭绘图窗口。干杯:)

The problem is that when you run from command line, when it ends, the plot windows disappear with it.

#! /usr/bin/octave -qf
f = figure;
set(f, "visible", "off")

t=0:0.001:5*pi;
plot(t, sin(5*t)), grid

print("MyPNG.png", "-dpng")

This saves output to MyPNG.png in the directory where it is run.

Then you might open it with a visualization program.

Another option is to add

pause

at the end of the program so it waits for user input to terminate, therefore to close the plot window.

Cheers :)

古镇旧梦 2024-12-03 16:50:55

也可以尝试等待按键。

while (waitforbuttonpress()==0)
暂停(1)
结尾

Also can try wait for key.

while (waitforbuttonpress ()==0)
pause(1)
end

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