一组数据处理(类似于数学有关问题)
一组数据处理(类似于数学问题)
我想处理一组数据,比如:20.1,20.3,25.3,26.1,30,50.1,80,80.1,79.8,80.25,40.1,31.2,25.7,25,21.2,21,红色的数据是我想要的数,如果画成图的话,类似于抛物线,不过抛物线的顶端比较平滑,就是有一组比较接近的值。那么我用程序怎么处理能得到红色部分的数据?欢迎大家讨论
------解决方案--------------------
如果你的条件是比较确定的话,就不需要太复杂的处理。
利用一个 Sorted = True 的 ListBox 控件:
Private Sub Command1_Click()
Dim strData As String, strItem() As String, i As Integer
Dim sngThreshold As Single, blnOver As Boolean, intTmp As Integer
sngThreshold = 5
strData = "20.1,20.3,25.3,26.1,30,50.1,80,80.1,79.8,80.25,40.1,31.2,25.7,25,21.2,21"
strItem = Split(strData, ",")
For i = 0 To UBound(strItem)
List1.AddItem strItem(i)
List1.ItemData(List1.NewIndex) = i
Next i
intTmp = List1.ItemData(List1.ListCount - 1)
For i = List1.ListCount - 2 To 0 Step -1
If CSng(List1.List(i + 1)) - CSng(List1.List(i)) > sngThreshold Then blnOver = True
If Not blnOver And intTmp > List1.ItemData(i) Then intTmp = List1.ItemData(i)
If blnOver Then List1.RemoveItem i
Next i
ReDim strItem(List1.ListCount - 1)
For i = 0 To List1.ListCount - 1
List1.ItemData(i) = List1.ItemData(i) - intTmp
strItem(List1.ItemData(i)) = List1.List(i)
Next i
'显示一下
For i = 0 To UBound(strItem)
Debug.Print strItem(i)
Next i
End Sub
------解决方案--------------------
既然是顶点附近,先求得最大值 80.1,然后选取两边与最大值相差不超过 1 的数,结果就是
80,80.1,79.8,80.25
我想处理一组数据,比如:20.1,20.3,25.3,26.1,30,50.1,80,80.1,79.8,80.25,40.1,31.2,25.7,25,21.2,21,红色的数据是我想要的数,如果画成图的话,类似于抛物线,不过抛物线的顶端比较平滑,就是有一组比较接近的值。那么我用程序怎么处理能得到红色部分的数据?欢迎大家讨论
------解决方案--------------------
如果你的条件是比较确定的话,就不需要太复杂的处理。
利用一个 Sorted = True 的 ListBox 控件:
Private Sub Command1_Click()
Dim strData As String, strItem() As String, i As Integer
Dim sngThreshold As Single, blnOver As Boolean, intTmp As Integer
sngThreshold = 5
strData = "20.1,20.3,25.3,26.1,30,50.1,80,80.1,79.8,80.25,40.1,31.2,25.7,25,21.2,21"
strItem = Split(strData, ",")
For i = 0 To UBound(strItem)
List1.AddItem strItem(i)
List1.ItemData(List1.NewIndex) = i
Next i
intTmp = List1.ItemData(List1.ListCount - 1)
For i = List1.ListCount - 2 To 0 Step -1
If CSng(List1.List(i + 1)) - CSng(List1.List(i)) > sngThreshold Then blnOver = True
If Not blnOver And intTmp > List1.ItemData(i) Then intTmp = List1.ItemData(i)
If blnOver Then List1.RemoveItem i
Next i
ReDim strItem(List1.ListCount - 1)
For i = 0 To List1.ListCount - 1
List1.ItemData(i) = List1.ItemData(i) - intTmp
strItem(List1.ItemData(i)) = List1.List(i)
Next i
'显示一下
For i = 0 To UBound(strItem)
Debug.Print strItem(i)
Next i
End Sub
------解决方案--------------------
既然是顶点附近,先求得最大值 80.1,然后选取两边与最大值相差不超过 1 的数,结果就是
80,80.1,79.8,80.25