首页 > 解决方案 > Gnuplot:拟合循环问题

问题描述

我需要用我用一些初始参数定义的高斯函数来拟合一些数据。我有 10 个 .gr 文件要拟合,代码告诉程序执行一个循环来拟合它们,然后绘制一个 .gif 文件以及数据的演变(每个文件对应于不同的时间)。该程序可以运行,并以 .gif 和 .dat 文件结束,但它会跳过一些 .gr 文件。代码是:

#Define the sequence number from ARG1 to variable id
id = ARG1

#Here we generate filename from sequence number we passed to this script by command call.
filename = sprintf("FeCoBSiNbCu%04d.gr",int(id))

#Command to fit the peak with background
fit [3.68:5.45] f45(x) filename u 1:2 via x4,A4,w4,x5,A5,w5,a0,a1

#Now we write all results into formatted string:
entry1 = sprintf("%d\t%.3f\t%.3f\t%.1f\t%.1f\t%.3f\t%.3f\t",int(id),x4,x4_err,A4,A4_err,w4,w4_err)
entry2 = sprintf("%.3f\t%.3f\t%.1f\t%.1f\t%.3f\t%.3f\t",x5,x5_err,A5,A5_err,w5,w5_err)

print entry1
print entry2

plot filename u 1:($0 >=0 ? $2 : 1/0) w p pt 6 ps 1 lc rgb "black" t "Experimental data",\
     filename u 1:((3.68 <= $1 && $1 <= 5.45) ? f45($1) : 1/0) w l lt 1 lw 3 lc rgb "red" t "Fitted data"

所以我用 4 位数字调用我拥有的所有文件,FeCoBSiNbCu%04d.gr但不考虑 0008 和 0009,而是在两种情况下都使用 0000。

我应该怎么办?

标签: gnuplotcurve-fittingdata-fitting

解决方案


推荐阅读