ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Operating Matrix in vba (https://www.excelbanter.com/excel-programming/390866-operating-matrix-vba.html)

infshare

Operating Matrix in vba
 
when i wanna get the solution of multiplying two matrix, i can use a
worksheet function.
worksheetfunction.mmult(MarixA, MatrixB)

but how can i get the solution of multiplying a number and a matrix without
using a user-defined function?



Alan Beban

Operating Matrix in vba
 
You can insert the following code:

newMatrix = MatrixA
For i = LBound(NewMatrix) To UBound(NewMatrix)
For j = LBound(NewMatrix, 2) To UBound(NewMatrix, 2)
newMatrix(i, j) = 3 * NewMatrix(i, j)
Next
Next

or you can put essentially identical code in a Function

Function DoNotCallMeUDF(iArray)
newMatrix = iArray
For i = LBound(newMatrix) To UBound(newMatrix)
For j = LBound(newMatrix, 2) To UBound(newMatrix, 2)
newMatrix(i, j) = 3 * newMatrix(i, j)
Next
Next
DoNotCallMeUDF = newMatrix
End Function

and code

newMatrix = DoNotCallMeUDF(MatrixA)

Why the prohibition on the latter???

Alan Beban

infshare wrote:
when i wanna get the solution of multiplying two matrix, i can use a
worksheet function.
worksheetfunction.mmult(MarixA, MatrixB)

but how can i get the solution of multiplying a number and a matrix without
using a user-defined function?




All times are GMT +1. The time now is 05:26 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com