ARF
ARF

Reputation: 21

GNUPLOT fit loop

I have a text file containing N colums and I would like to fit the data of each column using the command fit of GNUPLOT using a custum f(x), for example f(x)=exp(x/t), fitting via t. The first column of the text file contains the values of x. I do not manage to make a loop on the columns. Can anyone help me?

Thank you very much, Francesco

Upvotes: 1

Views: 650

Answers (1)

ARF
ARF

Reputation: 21

Maybe this is not the best piece of code but it works.

    #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  
}

Upvotes: 1

Related Questions