如何在Julia中对不均匀间隔阵列中的数据进行插值?
如何在Julia中使用最近邻插值构造间隔不均匀数据的插值?我在REPL上查看并键入以下内容:如何在Julia中对不均匀间隔阵列中的数据进行插值?,julia,interpolation,Julia,Interpolation,如何在Julia中使用最近邻插值构造间隔不均匀数据的插值?我在REPL上查看并键入以下内容: using Interpolations input = [1.0 60; 1.1 0; 2.0 60; 2.3 0; 4.0 430; 4.05 0] itp = interpolate(input[:,1], input[:,2], Gridded(Constant())) 这对我来说似乎很简单,但给出了: 错误:LoadError:MethodError:没有方法匹配 插值(::数组{Flo
using Interpolations
input = [1.0 60; 1.1 0; 2.0 60; 2.3 0; 4.0 430; 4.05 0]
itp = interpolate(input[:,1], input[:,2], Gridded(Constant()))
这对我来说似乎很简单,但给出了:
错误:LoadError:MethodError:没有方法匹配
插值(::数组{Float64,1},::数组{Float64,1},
::网格化{常数})
是否需要将数组
s转换为向量
s?如果是,怎么做?请告诉我有一个简单的解决方案…当你在一个N维空间中,你应该把插值“结”的坐标放在一个N元组的向量中。在1-D中,这表示类似于(x,)
的1元组,而不是普通的x
:
julia> input = [1.0 60; 1.1 0; 2.0 60; 2.3 0; 4.0 430; 4.05 0]
6×2 Array{Float64,2}:
1.0 60.0
1.1 0.0
2.0 60.0
2.3 0.0
4.0 430.0
4.05 0.0
julia> x = input[:, 1];
julia> y = input[:, 2];
julia> itp = interpolate((x,), y, Gridded(Constant()))
6-element interpolate((::Array{Float64,1},), ::Array{Float64,1}, Gridded(Constant())) with element type Float64:
60.0
0.0
60.0
0.0
430.0
0.0
julia> itp(1.01)
60.0
谢谢,这个有用。但是在测试之后,我注意到我正在使用前面的值寻找一个分段插值,类似于
GriddedInterplant(uuuu,'previous')
。Julia也可以这样做吗?我不确定目前插值中是否存在这样的功能。然而,它应该相当容易实现。也许这会是一个受欢迎的公关?公关,你的意思是“拉请求”?似乎是这样,但仍在等待…是的,这就是我的意思。很高兴看到雷达上有这个功能。。。