gnuplot的设置参数,从阵列中的bash脚本 [英] Set parameters of Gnuplot from array in bash script
问题描述
我试图加载使用bash脚本和绘图数据配置文件中的Gnuplot的参数。这个问题的关键是获得这些参数。这是我的解决方案的尝试,但有些错误发生。
I'm trying to load parameters of Gnuplot from configuration file using bash script and plotting data. The point of this problem is access to these parameters. This is my attempt of solution, but some errors occured.
gnuplot << EOF
values="${params[*]}"
do for [val in values] {
val=sprinf("%s", j)
set $val
}
我得到这样的输出:
I got this output:
gnuplot> do for [j in values] {
^
line 0: invalid complex constant
line 0: undefined variable: j
gnuplot> set
^
line 0: Unrecognized option. See 'help set'.
gnuplot> }
^
line 0: invalid character }
我敢肯定,我有参数数组内的多个字符串。
谢谢
I'm sure, I have multiple strings inside of params array. Thanks
推荐答案
您的gnuplot版本太旧。迭代结构为
仅支持从版本4.6。
Your gnuplot version is too old. The iteration structure do for
is supported only since version 4.6.
然后,以下工作正常:
#!/bin/bash
params[0]='grid'
params[1]='xrange[0:10]'
gnuplot -persist << EOF
values="${params[*]}"
do for [val in values] {
eval('set '.val)
}
plot x
EOF
但是,这只能如果数组项不包含任何空格。通常情况下,你会创建一个配置文件与内容
But that works only, if the array entries don't contain any white spaces. Usually, you would create a configuration file with the content
set grid
set xrange [0:10]
和负荷'config.gp
。
这篇关于gnuplot的设置参数,从阵列中的bash脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!