2015-12-16 60 views
1

我有一個包含N列的文本文件,我想用適合GNUPLOT的命令使用custum f(x)來適合每列的數據,例如f(x)= exp(x/t),通過t擬合。文本文件的第一列包含x的值。 我無法在列上進行循環。 任何人都可以幫助我嗎?GNUPLOT擬合循環

非常感謝你, 弗朗切斯科

+0

這有點複雜,請參閱我的答案:[gnuplot linear fit for for loop](http://stackoverflow.com/a/24367915/2604213) – Christoph

回答

1

也許這不是代碼最好的一塊,但它的工作原理。

#Given a txt file, where the first colum is x, this script calculates 
#the best fit for each column starting from column 2 
#N=number of column 
#(R0:R1)=range of x values over which calculate fit 
#The script saves parameters fit in file parameters.txt. 
#Remember to erase this file before relaunching because appends results. 

N=28 
R0=0 
R1=7 

do for [i=2:N:1] { 
    set terminal postscript enhanced color solid eps 
    set output graph(i) 
    set xrange[0:20] 

    f(x) = exp(-x/tau) 
    set fit errorvariables 
    fit [R0:R1] f(x) 'myfilename.txt' u 1:i via tau 

    set print "parameters.txt" append 
    print tau,tau_err 
    plot"myfilename.txt" u 1:i, f(x) 
    reset 
}