刚接触VB一天,代码求助
刚接触VB一天,代码求助一直用的是matlab,由于一个代码不会用matlab编程 故找大神借用了vb代码
求助:如何在vb6.0运行代码 数据如何输入运行
问题比较垃圾 还请大神不吝赐教(毕业论文需要,无奈呀)
代码如下:
Public Function Yamamoto(data() As Double, SNR() As String, a As Double) 'Yamaoto 突变性检验(检验突变点)
''Data 存储两列数据,第一列时间数据,第二列观测数据
'SNR 存储两列数据,第一列时间数据,第二列观测数据
Dim m1 As Long, m2 As Long
Dim n1 As Long, n2 As Long
Dim i As Long, j As Long
Dim Ex1 As Double, Ex2 As Double
Dim Std1 As Double, Std2 As Double
Dim max As Double, max_num As Long
On Error GoTo Yamo:
m1 = LBound(data, 1)
n1 = UBound(data, 1)
m2 = LBound(data, 2)
n2 = UBound(data, 2)
ReDim SNR(m1 To n1 - 3, m2 To n2)
i = m1 + 1
Do While (i < n1 - 1)
Ex1 = 0
Std1 = 0
For j = m1 To i
Ex1 = Ex1 + data(j, n2)
Std1 = Std1 + data(j, n2) * data(j, n2)
Next
Ex1 = Ex1 / (i - m1 + 1)
Std1 = Sqr(Std1 / (i - m1) - Ex1 * Ex1)
Ex2 = 0
Std2 = 0
For j = i + 1 To n1
Ex2 = Ex2 + data(j, n2)
Std2 = Std2 + data(j, n2) * data(j, n2)
Next
Ex2 = Ex2 / (n1 - i)
Std2 = Sqr(Std2 / (n1 - i - 1) - Ex2 * Ex2)
SNR(i - 1, m2) = data(i, m2)
SNR(i - 1, n2) = Abs(Ex1 - Ex2) / (Std1 + Std2)
If i = m1 + 9 Then
max = SNR(i - 1, n2)
Yamamoto = SNR(i - 1, m2)
If (n1 - i) > (i - m1 + 1) Then
max_num = i - m1 + 1
Else
max_num = n1 - i
End If
ElseIf (n1 - i) > 9 And (i > m1 + 9) Then
If max < SNR(i - 1, n2) Then
max = SNR(i - 1, n2)
Yamamoto = SNR(i - 1, m2)
If (n1 - i) > (i - m1 + 1) Then
max_num = i - m1 + 1
Else
max_num = n1 - i
End If
End If
End If
i = i + 1
Loop
If max > Hydrological_S.T_INV(n1 - m1 - 1, 1 - a / 2) / Sqr(max_num) Then
Yamamoto = "The change point is :" & Yamamoto & " with signficance(suggested)"
Exit Function
Else
Yamamoto = "The change point is :" & Yamamoto & " with no signficance(suggested)"
Exit Function
End If
Yamo:
Yamamoto = "Error:"
End Function