gpt4 book ai didi

bash - 如何在 gnuplot 上将变量传递给 -e?

转载 作者:行者123 更新时间:2023-11-29 09:31:59 25 4
gpt4 key购买 nike

我想定义一个 png 文件的 gnuplot 输出。如何在 gnuplot 上定义 fileName

    #This lines and also Traffic$j are define on my bash file.
# Traffic$j is the name of file and that is valid. Traffic$j is on the loop
# j is loop index
.
.

fileName=Traffic$j
.
.

我试试这个:

gnuplot -e "filename=${!fileName}" plotFile

但是我遇到了这个错误:

line 0: constant expression required

我试试 ruakh 的想法:

gnuplot -e "filename = '${!fileName}'" plotFile

但我拒绝了这个警告:

"plotFile", line 12: warning: Skipping data file with no valid points

第 12 行?看看我的脚本的最后一行。

如何在 gnuplot 上将变量传递给 -e 开关?

更新:我的绘图文件是这样的:

set terminal png size 720,450 enhanced font "H,11"
set output filename . '.png'

plot '../_numXY' using 2:3:(sprintf('%d', $1)) with labels offset 0,1 point pointtype 7 ps 2 lc rgb "green" notitle, \
filename using 1:2:($3-$1):($4-$2) with vectors linewidth 6 lc rgb "blue" notitle #line 12

最佳答案

问题不在于如何传递变量,而在于如何引用字符串。例如,如果 $j3$Traffic3file.txt,那么您传递给 -e 的是 filename=file.txt,当你需要传递的是类似 filename = "file.txt"文件名 = 'file.txt'。所以:

gnuplot -e "filename = '${!fileName}'" plotFile

编辑添加:在评论中,您写:

thanks, $Traffic3 is not file.txt. or better to say I do not have $Traffic3 but I have Traffic3. Traffic3 is not parameter. It is the name of of file itself and not refer to another thing like file.txt

这意味着您不应该编写 ${!fileName},而应该编写 $fileName。符号 ${!fileName} 的意思大致是,“好的,所以 $fileName 的值是另一个变量的名称。给我那个变量的值。”所以你只想:

gnuplot -e "filename = '$fileName'" plotFile

关于bash - 如何在 gnuplot 上将变量传递给 -e?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25258700/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com