我有一个数据文件example.dat
例如,使用 xy 值
0 10
1 40
5 20
我如何对这些点的线性插值进行采样gnuplot
?我想将该采样存储在另一个文件中output.dat
using set table
。通过三次样条平滑我可以做到
set table "output.dat"
set samples 10
plot "example.dat" smooth csplines
这会产生 10 个点的三次样条插值的等距采样。但我发现没有办法用线性插值进行这样的等距采样:采样率被忽略(gnuplot 5.0)。
我尝试在没有任何选项的情况下使用线性插值“平滑”,例如smooth unique
,希望这能让 gnuplot 将数据集视为可以采样的函数,但无济于事。
我的应用程序正在公共网格中对不同的数据文件进行采样,以供以后比较。我知道这正在突破 gnuplot 的用途界限,但由于已经有一个采样机制,我想知道我是否只是错过了一些东西。
如果您仍然对此感兴趣,以下是“仅 gnuplot”解决方案。不是很优雅,但似乎可行。
### "gnuplot only" linear interpolation of data
reset session
$Data <<EOD
0 10
1 40
5 20
EOD
stats $Data u 1 nooutput
min = STATS_min
max = STATS_max
Samples=10
Interpolate(x0,y0,x1,y1,xi) = y0 + (y1-y0)/(x1-x0)*(xi-x0)
set print $Interpol
set table $Nowhere
do for [i=1:Samples] {
xi = min + (i-1)*(max-min)/(Samples-1)
do for [j=0:STATS_records-1] {
plot $Data u (a=$1,$1):(b=$2,$2) every ::j::j with table
plot $Data u (c=$1,$1):(d=$2,$2) every ::j+1::j+1 with table
if ( xi>=a && xi<=c) {
print sprintf("%g\t%g",xi,Interpolate(a,b,c,d,xi))
break
}
}
}
unset table
set print
set colorsequence classic
plot $Data u 1:2 w lp t "original data",\
$Data u 1:2 w lp smooth cspline t "smooth cspline",\
$Interpol u 1:2 w p pt 6 t "linear interpolation"
### end code
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)