I've found here a quite helpful code for looping a fit through multiple data sets with the y-values in separate columns in one file. Each parameter is printed on the graph. Now, I was wondering how to extend the code so all parameters are listed in another .txt file.
I've tried to use the set print 'parameters.dat' and print a,b,c function, but this resulted in having only the parameters of the last fit. But I'd like to have the parameters of every fit in one file. I'm using Gnuplot 5.4 on Windows 10.
One way gnuplot can print text to files is: (check help set print
)
set print FILE # open file
print sprintf("%g %g", x, y) # or whatever...
set print # close file
So, if you want to print the fitting results of each iteration into a different file, you can add the following into the loop:
do for [i=1:3] {
# do the fitting or whatever
set print sprintf("FitResults%02d.txt",i)
print sprintf("a = %g", a)
print sprintf("b = %g", b)
print sprintf("c = %g", c)
set print # close file
}
or all in the same file:
set print sprintf("FitResults.txt")
do for [i=1:3] {
# do the fitting or whatever
print sprintf("Fit number: %d",i)
print sprintf("a = %g", a)
print sprintf("b = %g", b)
print sprintf("c = %g", c)
print "" # empty line as separator
}
set print # close file