如何动态地进行数据的线性插值与遗漏值的行?(How to dynamically do a line

2019-10-29 22:37发布

我有这样的数据

Date    Data
8/25/2017   980
8/24/2017   64
8/23/2017   593   
8/22/2017   595
8/21/2017   
8/20/2017   
8/19/2017   794
8/18/2017   437
8/17/2017   
8/16/2017   
8/15/2017   
8/14/2017   629

如果我在小区8月21日想(794-595)/ 3和2 *(794-595)/ 3细胞8月22日,同样(629-437)/ 4在8月17日,2 *(629-437)/ 4在8月16日等...

如何做到这一点动态,不考虑两者之间缺失值的数量

Answer 1:

下面的代码提供了一个解决方案,以及GIF动画显示的代码解决您的问题。 当然,也有解决这个问题的方法很多,但是这很简单。 至少,这说明你将需要什么样的输入。 它假定由1递增x值(如你在你的数据)。 否则,你需要使用类似的斜率拦截功能。

Option Explicit
Sub interpolate()
Dim r As Range, cell As Range
Set r = Application.InputBox("select interpolation range", , , Type:=8)
For Each cell In r
  If cell = "" Then
    cell = r(1) + (r(r.Rows.Count) - r(1)) * (cell.row - r.row) / (r(r.Rows.Count).row - r(1).row)
  End If
Next
End Sub


文章来源: How to dynamically do a linear interpolation of data in a row with missing values?