■102876 / ) |
Re[4]: このエラーを解消したいです。 |
□投稿者/ shu (1回)-(2024/01/21(Sun) 19:49:31)
|
> > Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click > Dim y() As Double 'データが入る配列 > Dim N As Integer = 5 > Dim M As Integer = 2 > Dim result As Double
ここまでにyの配列に値を設定する処理が入る?
> result = SGFilter(y(), N, M) result = SGFilter(y, N, M) ※既出の回答通り多分これ
> End Sub > > Private Function SGFilter(ByVal y() As Double, ByVal N As Integer, ByVal M As Integer) As Double() > Dim i As Integer, j As Integer, k As Integer > Dim w(0 To N, 0 To M) As Double > Dim sum As Double > Dim y2() As Double > > ReDim y2(0 To UBound(y)) 下でいきなり足し算を行っているでのy2の中身を初期化する処理があった方がよい
> > For i = 0 To UBound(y) > sum = 0 > For j = -N To N > For k = 0 To M > w(N + j, k) = ((j + k) ^ (2 * M)) > Next k > sum = sum + w(N + j, 0) > Next j > For j = -N To N > For k = 0 To M > w(N + j, k) = w(N + j, k) / sum > Next k > Next j ※1 > For j = -N To N > sum = 0 y2(i)がこのループで変動しない為※1に移動した方がよい
> For k = 0 To M > sum = sum + w(N + j, k) * y(i + j) ※i+jがyのインデックス最大値を超える為エラーとなる。ifなどでインデックスチェックが必要
> Next k > y2(i) = y2(i) + sum y2(i)がこのループで変動しない為※2に移動した方がよい
> Next j ※2
> Next i > SGFilter = y2 > End Function > >
|
|