【发布时间】:2019-09-26 06:44:39
【问题描述】:
我想制作一个 gif 文件,对名称为 1.dat、2.dat 的文件进行迭代...我已尝试使用此代码:
!/usr/bin/gnuplot
unset key
plot "dades.dat" using 1:2 #
h=GPVAL_DATA_Y_MIN #1.69794089321728966E-045 #
plot "dades.dat" using 1:3 #------>Dummy plots per tal de guardar en
variables
d=GPVAL_DATA_Y_MIN #7.12168589558569665E-046 # els valors ses amplades de ses malles
plot "dades.dat" using 1:4 #
c=GPVAL_DATA_Y_MIN #
plot "dades.dat" using 1:5 #
lam=GPVAL_DATA_Y_MIN #
plot "dades.dat" using 1:6 #
n=GPVAL_DATA_Y_MIN #
i=0
set terminal gif
unset key
set output "film.gif"
set title "V(x)"
set xlabel "x(m)"
set ylabel "V(V)"
i=i+1
if( i < n ) reread;
但是当我使用终端执行时,我的变量不会改变,也不会停止循环。
后来我用其他形式来做循环,比如:
do for [i=0:n] {
infile(i) = sprintf("%d.dat",i)
print i
plot infile(i) w l using 1:2
}
但是,当我执行时,终端会显示下一个错误:
do for [i=0:n] {
^
"./film.gnuplot", line 22: invalid complex constant
非常奇怪,因为我已经安装了 4.6 版本的 gnuplot。然后我试着把终端 gnuplot ./film.gnuplot 放进去然后给我看:
set terminal gif
^
"film.gnuplot", line 15: unknown or ambiguous terminal type; type just 'set terminal' for a list
最后,我执行了 gnuplot,我编写了帮助终端命令并显示我已经安装了所有这些终端:
canvas cgm context corel
dumb dxf eepic emf
emtex epslatex fig gpic
hp2623a hp2648 hpgl imagen
latex mf mif mp
pcl5 pop postscript pslatex
pstex pstricks push qms
regis svg tek40xx tek410x
texdraw tgif tkcanvas tpic
vttek xterm
非常奇怪,因为我总是使用 png 终端并且从不显示错误,但是当我使用 gnuplot 执行时,它会显示错误。
我正在使用 Ubuntu
【问题讨论】:
-
如果你运行
gnuplot --version,输出是什么?奇怪的是,正如您所说,您通常使用 png 终端但它没有被列为已安装。您也可以在 gnuplot 中运行print GPVAL_TERMINALS来检查安装了哪些终端。 -
感谢回答。如果我运行 gnuplot --version,它显示我有 gnuplot 4.6 patchlevel 5
-
奇怪。您使用的是哪个操作系统?您是自己编译/安装 gnuplot 还是使用软件包?我看到的一件事是您使用
i作为循环计数器和变量,而gnuplot 抱怨invalid complex constant,可能是因为它试图使用i来表示-1 的平方根。尝试使用不同的变量名(例如ii)。i表示复杂常量的问题在很多语言中都是通用的,所以不要将i和j用作变量是一个好习惯。 -
我使用的是 Ubuntu,我手动安装了 gnuplot(直接从 gnuplot 网站下载,从终端开始安装)。关于变量的名称,我更改了它,但错误消息仍然显示。
-
@andyras Gnuplot 使用符号
{0,1}表示虚数常数i。由于 4.4 版不知道do for循环,因此它需要在左括号后有一个复数。