ProductName  

Subtracts another matrix from the current matrix object.

Syntax

MatrixObject.MinusEquals MatrixToSubtract

Parameters

MatrixToSubtract
The matrix that you wish to subtract from current matrix.

Remarks

Both matrices must be of the same size (Rows and Cols properties must be equal).

Unlike the Minus Method, MinusEquals does not create a new matrix but subtracts from the current matrix elements.

Error Codes

Error 1312 will be returned if the matrices are not of the same size.

Example

This example demonstrates the use of the PlusEquals and MinusEquals methods.
Private Sub MatrixPlusMinusEquals()

Dim A As Matrix, B As Matrix

    Set A = New Matrix
    A.Size 5, 5
    A.FillRandom
    Debug.Print "A ="
    Debug.Print A.GetString(0)
    
    Set B = New Matrix
    B.Size 5, 5
    B.FillRandom
    Debug.Print "B ="
    Debug.Print B.GetString(0)
    
    A.PlusEquals B
    Debug.Print "A + B = "
    Debug.Print A.GetString(0)
    
    A.MinusEquals B
    Debug.Print "A - B = "
    Debug.Print A.GetString(0)
 
End Sub

Output

A =
|  6  2  8  6  5 |
|  4  9  8  7  2 |
|  9  7  5  3  0 |
|  1  4  1  2 10 |
|  4  1  0  0  4 |

B =
|  6  6  6  2  7 |
|  5  4  1  6  8 |
|  8  5  3  9  7 |
| 10  9  5  1  5 |
|  2  9  2  8  8 |

A + B = 
| 12  8 14  8 12 |
|  9 13  9 13 10 |
| 17 12  8 12  7 |
| 11 13  6  3 15 |
|  6 10  2  8 12 |

A - B = 
|  6  2  8  6  5 |
|  4  9  8  7  2 |
|  9  7  5  3  0 |
|  1  4  1  2 10 |
|  4  1  0  0  4 |

See Also

Plus Method | Minus Method | PlusEquals Method

Applies To: Matrix | CMatrix