使用多个文件和不同的单位拟合函数



我想对gnuplot中的多个文件使用fit命令。我知道,对于多个文件,如果对列的操作相同,则命令为:

f(x)=a*x+b
fit f(x) '< cat file1 file2 file3' using ($18/-200):($4/200) via a,b

现在,我不想做相同的操作($18/-200):($4/200),而是想做不同的操作(因为例如,文件具有相同的数量,但单位不同);例如对于文件1 ($18/-200):($4/200)和对于文件2 ($3*200):($7/400)。命令

fit f(x) '< cat file1 file2' using '($18/-200):($4/200) ($3*200):($7/400)'  via a,b

我天真地尝试了一下,但没有用。有什么提示吗?这个问题类似于如何在gnuplot 中适应具有多个文件的函数

感谢

如果您已经在使用bash命令,那么您可以使用awk来预处理您的数据:

# Get number of lines in file 1
n1 = word(system("wc -l file1"), 1)
# Create command to preprocess data
filename = "< cat file1 file2 | awk '{if(NR < 1+".n1."){print $18/-200., $4/200.} else{print $3*200, $7/400.}}'"
fit f(x) filename using 1:2 via a,b

或者在bash:中生成一个temp文件

n1=`wc -l file1 | awk '{print $1}'`
cat file1 file2 | awk -v n1=$n1 '{if(NR < 1+n1){print $18/-200., $4/200.} else{print $3*200, $7/400.}}' > temp

并将其用于gnuplot中的拟合:

fit f(x) temp using 1:2 via a,b

最新更新