【问题标题】:Fit many pieces of data in Gnuplot's for loop在 Gnuplot 的 for 循环中拟合许多数据
【发布时间】:2015-04-23 15:48:40
【问题描述】:

数据

Model Decreasing-err Constant-err Increasing-err
2025 73-78 80-85 87-92 
2035 63-68 80-85 97-107 
2050 42-57 75-90 104.5-119.5 

here 描述了哪个数据结构(使用 -err)。

为了绘制点,我运行

set terminal qt size 560,270; 
set grid; set offset 1,1,0,0; 
set datafile separator " -"; 
set key autotitle columnhead;
plot for [i=2:6:2] "data.dat" using 1:(0.5*(column(i)+column(i+1))):(0.5*(column(i+1)-column(i))) with yerror; 

得到

但是,我想为这些点添加一条线,由于扭结,您不能仅使用 with yerrorlines 来完成。

我的用于拟合递增和递减线的伪代码

inc(x) = k1*x + k2; 
con(x) = n1*x + n2;
dec(x) = m1*x + m2;
fit inc(x), con(x) dec(x) for [i=2:6:2] "data.dat" 
   using 1:(0.5*(column(i)+column(i+1))):(0.5*(column(i+1)-column(i))) 
   via k1,k2,n1,n2,m1,m2; 

问题在于将函数fit 与for 循环一起使用。

如何在 for 循环中使用 Gnuplot 的 fit? 我想同时为数据拟合多条线。

【问题讨论】:

    标签: for-loop plot gnuplot


    【解决方案1】:

    我会使用 doeval 来做到这一点:

    # Define your functions (you can also use do + eval to do this)
    f1(x) = a1*x+b1
    f2(x) = a2*x+b2
    f3(x) = a3*x+b3
    
    # Loop
    do for [i=1:3] {
    eval sprintf("fit f%g(x) 'data.dat' u 0:%g via a%g, b%g", i, i, i, i)
    }
    

    您可以根据自己的目的调整上述内容。

    【讨论】:

    • 如何将其作为单线运行?我运行f1(x) = a1*x+b1; f2(x) = a2*x+b2; f3(x) = a3*x+b3; do for [i=1:3] { eval sprintf("fit f%g(x) model1_range.dat' u 0:%g via a%g, b%g, i, i, i, i) }。但它停留在提示 more 中。
    • @Masi 您在数据文件名前缺少单引号,在字符串末尾缺少双引号。
    • 我仍然得到相同的f1(x) = a1*x+b1; f2(x) = a2*x+b2; f3(x) = a3*x+b3; do for [i=1:3] { eval sprintf("fit f%g(x) 'model1_range.dat' u 0:%g via a%g, b%g, i, i, i, i) },停留在提示符more中。
    • 字符串末尾仍然缺少双引号:它应该是 b%g", 而不是 b%g,
    猜你喜欢
    • 1970-01-01
    • 2016-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多