1

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

ARF
  • 21
  • 3
  • That is a bit complicated, see my answer here: [gnuplot linear fit within for loop](http://stackoverflow.com/a/24367915/2604213) – Christoph Dec 16 '15 at 14:42

1 Answers1

1

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  
}
ARF
  • 21
  • 3