使用 sed 和 gnuplot 循环绘制文件中的特定行
Using sed with gnuplot to plot specific lines from a file in a loop
我想在 gnuplot 脚本中用循环绘制图片,但是 "sed" 行有问题。有人知道怎么解决吗?
这是我的脚本:
do for [i=1:2] {
str_n=sprintf('%d',i)
set term png
set output str_n.'.png'
plot "<(sed -n '(1+45*(i-1)),(45+45*(i-1))p file.dat'" u 2:5 w l
set output
}
在你的字符串中尝试这样的东西
sed -n '$(( (1+45*(${i}-1)) )),$(( (45+45*(${i}-1)) )) p' file.dat"
还有 <(
有点奇怪,因为我不知道字符串的这一部分还是尝试重定向,但我猜最后至少缺少一个 )
以防万一字符串模式。
您似乎在尝试在 sed 命令中使用 gnuplot 循环变量 i
。为了做到这一点,我会在构建 sed 命令时使用 sprintf
:
cmd = sprintf("<sed -n '%d,%dp' file.dat", 1+45*(i-1), 45*i)
plot cmd u 2:5 w l
这允许您在构造 sed 命令之前使用 gnuplot 计算数字。
更好的是,您应该使用 gnuplot 的内置功能来绘制特定范围的线条:
plot "file.dat" every ::(1+45*(i-1))::(45*i)
我想在 gnuplot 脚本中用循环绘制图片,但是 "sed" 行有问题。有人知道怎么解决吗?
这是我的脚本:
do for [i=1:2] {
str_n=sprintf('%d',i)
set term png
set output str_n.'.png'
plot "<(sed -n '(1+45*(i-1)),(45+45*(i-1))p file.dat'" u 2:5 w l
set output
}
在你的字符串中尝试这样的东西
sed -n '$(( (1+45*(${i}-1)) )),$(( (45+45*(${i}-1)) )) p' file.dat"
还有 <(
有点奇怪,因为我不知道字符串的这一部分还是尝试重定向,但我猜最后至少缺少一个 )
以防万一字符串模式。
您似乎在尝试在 sed 命令中使用 gnuplot 循环变量 i
。为了做到这一点,我会在构建 sed 命令时使用 sprintf
:
cmd = sprintf("<sed -n '%d,%dp' file.dat", 1+45*(i-1), 45*i)
plot cmd u 2:5 w l
这允许您在构造 sed 命令之前使用 gnuplot 计算数字。
更好的是,您应该使用 gnuplot 的内置功能来绘制特定范围的线条:
plot "file.dat" every ::(1+45*(i-1))::(45*i)