从数据文件中为 gnuplot 函数赋值
Assign a value to a gnuplot function out of a data file
在 Gnuplot 中,我尝试从两列数据文件中为函数 f(x) 赋值,以便将该函数绘制为一条水平线。
f(x)=value of at ==2 from filename.dat
plot 'filename.dat' , ' ' x<=2?f(x):1/0
我试过了:
awk '==2,print{}' filename.dat
但它说:
Warning: encountered a string when expecting a number
Did you try to generate a file name using dummy variable x or y?".
有什么建议吗?
P.S.: 我知道awk后面应该有一个<
符号,但是这里不会显示
我建议采用这种方法:
filename = "test.txt"
y = system(sprintf("awk '==2{print }' %s", filename))
f(x)=real(y)
plot filename u 1:2 w l, f(x) t ''
gnuplot 似乎将 y
的值解释为字符串。因此,我们必须强制转换为数字,我通过将其转换为 real
数字来实现。 (另一种可能f(x)=y+0
)
这是我的演示 test.txt
的输出,内容如下:
1 1
2 0.5
3 0
在 Gnuplot 中,我尝试从两列数据文件中为函数 f(x) 赋值,以便将该函数绘制为一条水平线。
f(x)=value of at ==2 from filename.dat
plot 'filename.dat' , ' ' x<=2?f(x):1/0
我试过了:
awk '==2,print{}' filename.dat
但它说:
Warning: encountered a string when expecting a number Did you try to generate a file name using dummy variable x or y?".
有什么建议吗?
P.S.: 我知道awk后面应该有一个<
符号,但是这里不会显示
我建议采用这种方法:
filename = "test.txt"
y = system(sprintf("awk '==2{print }' %s", filename))
f(x)=real(y)
plot filename u 1:2 w l, f(x) t ''
gnuplot 似乎将 y
的值解释为字符串。因此,我们必须强制转换为数字,我通过将其转换为 real
数字来实现。 (另一种可能f(x)=y+0
)
这是我的演示 test.txt
的输出,内容如下:
1 1
2 0.5
3 0