我有6分钟间隔收集的现有数据。时间戳在A列中,相应的值在B列中。
我想插入这些数据以获得一分钟细分,使用基本插值方法计算。所需输出的样本显示在D和E列中。
有没有办法让这个计算自动化?
答案 0 :(得分:2)
您可以尝试从E1
填写
=PERCENTILE(B$1:B$7,PERCENTRANK(A$1:A$7,D1,30))
(假设值不减少。)
答案 1 :(得分:0)
我编写了自己的插值函数。它不是为日期设计的,因此您需要修改参数。这可能是一个很好的起点。第一个参数是要插入的数据点。第二个参数是定义曲线的输入数据范围。注意,当数据点超出范围时,返回值将是最接近的数据点,而不是外推值。
Function interpolate(inp As Double, rng As Range)
' written by: Todd Wegner
'
' inp --> the data point to interpolate
' rng --> the range of original data
'
' early binding
Dim i As Long, dim1 As Long
Dim x1 As Double, x2 As Double, y1 As Double, y2 As Double
Dim arr As Variant
'
' set array to the Range(rng)
arr = rng
'
' if the input is below the data bounds
' use the first data point, DO NOT extrapolate
If inp < arr(1, 1) Then
interpolate = arr(1, 2)
Exit Function
End If
'
' get array upper bound
dim1 = UBound(arr)
'
' if the input is above the data bounds
' use the last data point, DO NOT extrapolate
If inp > arr(dim1, 1) Then
interpolate = arr(dim1, 2)
Exit Function
End If
'
' inputs that lie within the data range get interpolated
i = 1
Do Until inp < arr(i, 1)
i = i + 1
Loop
x1 = arr(i - 1, 1)
x2 = arr(i, 1)
y1 = arr(i - 1, 2)
y2 = arr(i, 2)
'
' return
interpolate = (y2 - y1) / (x2 - x1) * (inp - x1) + y1
'
End Function