C
costanza99g
Hi,
I'm trying to subtract all the individual elements of two matrices.
One of the matrices is calculated using this function:
Function CovarianceMatrix(rng As Range) As Variant
Dim i As Integer
Dim j As Integer
Dim colnum As Integer
Dim rownum As Integer
Dim auxCovarianceMatrix() As Variant
colnum = rng.Columns.Count
' covariance matrix
ReDim auxCovarianceMatrix(colnum - 1, colnum - 1)
For i = 1 To colnum
For j = 1 To colnum
auxCovarianceMatrix(i - 1, j - 1) = Application.WorksheetFunction.Covar(rng.Columns(i), rng.Columns(j))
Next j
Next i
CovarianceMatrix = auxCovarianceMatrix
End Function
the other matrix (named avcovariancematrix) is calculated using a very similar formula.
I verified that both of these functions work well in the worksheet.
Now I need to subtract all the individual elements of both matrices (basic matrix operation), but I'm getting errors and I don't understand why.
I created a new function that calls the function I posted above and the other one.
This is the function I'm using:
Function AddMAtrix(rng as range) as variant
Aux1=CovarianceMatrix(rng)
Aux2=AverageCovarianceMatrix(rng)
AddMatrix=Aux1-Aux2
end function
thanks
I'm trying to subtract all the individual elements of two matrices.
One of the matrices is calculated using this function:
Function CovarianceMatrix(rng As Range) As Variant
Dim i As Integer
Dim j As Integer
Dim colnum As Integer
Dim rownum As Integer
Dim auxCovarianceMatrix() As Variant
colnum = rng.Columns.Count
' covariance matrix
ReDim auxCovarianceMatrix(colnum - 1, colnum - 1)
For i = 1 To colnum
For j = 1 To colnum
auxCovarianceMatrix(i - 1, j - 1) = Application.WorksheetFunction.Covar(rng.Columns(i), rng.Columns(j))
Next j
Next i
CovarianceMatrix = auxCovarianceMatrix
End Function
the other matrix (named avcovariancematrix) is calculated using a very similar formula.
I verified that both of these functions work well in the worksheet.
Now I need to subtract all the individual elements of both matrices (basic matrix operation), but I'm getting errors and I don't understand why.
I created a new function that calls the function I posted above and the other one.
This is the function I'm using:
Function AddMAtrix(rng as range) as variant
Aux1=CovarianceMatrix(rng)
Aux2=AverageCovarianceMatrix(rng)
AddMatrix=Aux1-Aux2
end function
thanks