MATLAB - Addition & Subtraction of Matrices



You can add or subtract matrices. Both the operand matrices must have the same number of rows and columns.

Example

Create a script file with the following code −

a = [ 1 2 3 ; 4 5 6; 7 8 9];
b = [ 7 5 6 ; 2 0 8; 5 7 1];
c = a + b
d = a - b

When you run the file, it displays the following result −

c =
      8     7     9
      6     5    14
      12    15    10
d =
      -6    -3    -3
      2     5    -2
      2     1     8
matlab_matrics.htm
Advertisements