10
Tôi đang cố chuyển dữ liệu từ 2 Mảng đôi thành 2 Mảng đôi khác nhau. Tôi không chắc chắn kích thước sẽ là gì bởi vì tôi lấy một mẫu ngẫu nhiên ra khỏi mảng đầu tiên và đặt nó vào mảng thứ hai.ReDim Bảo toàn "Subscript Out of Range"
Khi tôi thêm dòng ReDim Preserve, tôi nhận được lỗi Subscript Out of Range.
Function CreateTrainingSet(TrainingPercent As Double, Inputs() As Double, Outputs() As Double)
' Create Randomized Training set data
Dim TrainingInputs() As Double, TrainingOutputs() As Double
Dim i As Integer, j As Integer, count As Integer
'ReDim TrainingInputs(UBound(Inputs, 1), UBound(Inputs, 2))
'ReDim TrainingOutputs(UBound(Outputs, 1), UBound(Outputs, 2))
count = 0
' Move TraningPercent % of data from Inputs and Outputs to TrainingInputs and TrainingOutputs
For i = LBound(Inputs, 1) To UBound(Inputs, 1)
Dim ran As Double
ran = Rnd()
If ran <= TrainingPercent Then
count = count + 1
For j = LBound(Inputs, 2) To UBound(Inputs, 2)
ReDim Preserve TrainingInputs(1 To count, 1 To UBound(Inputs, 2))
TrainingInputs(count, j) = Inputs(i, j)
Next j
For j = LBound(Outputs, 2) To UBound(Outputs, 2)
ReDim Preserve TrainingOutputs(1 To count, 1 To UBound(Outputs, 2))
TrainingOutputs(count, j) = Outputs(i, j)
Next j
End If
Next i
For i = LBound(TrainingInputs, 1) To UBound(TrainingInputs, 1)
For j = LBound(TrainingInputs, 2) To UBound(TrainingInputs, 2)
Cells(i, j + 10).Value = TrainingInputs(i, j)
Next j
Next i
End Function
Bạn có gặp lỗi trên dòng 'redim preserve' không? – PowerUser
Bạn chỉ có thể redim * cuối * kích thước của một mảng 2-D khi sử dụng 'Preserve'. –
Cảm ơn Tim. Có cách nào khác để làm điều này sau đó? – atomant