slb.expert
Thành viên mới

- Tham gia
- 1/10/12
- Bài viết
- 5
- Được thích
- 0
I got the VBA code to create the bin and frequency for Histogram purpose. But I know what happen to my code, it didnt run and report "Type mismatch". Could anyone pls help. Thank you very much:
PHP:
Sub Test()
Dim Data As Variant
'M = 40
Set Data = ActiveSheet.Range("C2:C65536")
ReDim Arr(Data) As Single
Call Hist(40, Arr)
End Sub
Sub Hist(M As Long, Arr() As Single)
Dim i As Long, j As Long
Dim Length As Single
ReDim breaks(M) As Single
ReDim freq(M) As Single
Dim Data As Long
'Assign initial value for the frequency array
For i = 1 To M
freq(i) = 0
Next i
'Linear interpolation
Length = (Arr(UBound(Arr)) - Arr(1)) / M
For i = 1 To M
breaks(i) = Arr(1) + Length * i
Next i
'Counting the number of occurrences for each of the bins
For i = 1 To UBound(Arr)
If (Arr(i) <= breaks(1)) Then freq(1) = freq(1) + 1
If (Arr(i) >= breaks(M - 1)) Then freq(M) = freq(M) + 1
For j = 2 To M - 1
If (Arr(i) > breaks(j - 1) And Arr(i) <= breaks(j)) Then freq(j) = freq(j) + 1
Next j
Next i
'Display the frequency distribution on the active worksheet
For i = 1 To M
Cells(i, 1) = breaks(i)
Cells(i, 2) = freq(i)
Next i
End Sub
Chỉnh sửa lần cuối bởi điều hành viên: