Sub HMM()
Dim x As Integer
Dim GG As Integer
Dim Gr As Integer
Dim rG As Integer
Dim rr As Integer
For x = 3 To x = 26126
If ActiveSheet.Cells(x, 3) > 0 And ActiveSheet.Cells(x + 1, 3) > 0 Then
GG = GG + 1
End If
If ActiveSheet.Cells(x, 3) > 0 And ActiveSheet.Cells(x + 1, 3) < 0 Then
Gr = Gr + 1
End If
If ActiveSheet.Cells(x, 3) < 0 And ActiveSheet.Cells(x + 1, 3) > 0 Then
rG = rG + 1
End If
If ActiveSheet.Cells(x, 3) < 0 And ActiveSheet.Cells(x + 1, 3) < 0 Then
rr = rr + 1
End if
Next x
With ActiveSheet
.Cells(2, 30) = GG
.Cells(3, 30) = Gr
.Cells(4, 30) = rG
.Cells(5, 30) = rr
End With
End Sub
所以我有一长串数字,从 C3 到 C26126。我需要做的是找出正数在正数(GG)之前多少次,负数在正数之前多少次(rG)等等。所以我需要GG Gr rG和rr。对不起,如果这还不够清楚。
示例:我有一个表 y:[-1,2,2,3,-1,-2,2] GG = 2, Gr = 1, rG = 2, rr = 1
我的最终目标是为我的时间序列找到一个简单的隐马尔可夫模型。