Deleting row or column in matrix:
An empty braces [] will define the entire row and column of a matrix is deleted. Let us consider an example deleting 2nd row of the:
a = [3 4 5 6 7; 2 3 4 5 6; 1 2 3 4 5; 4 5 6 7 8];
a ( 2 , : ) = []
if we want to delete the 3rd column of the given example
a = [2 3 4 5 6; 1 2 3 4 5; 3 4 5 6 7; 4 5 6 7 8];
a(: , 3)=[]
Matrix Operation:
Now let us discuss some commonly used matrix operations are:
Addition and subtraction of matrix:
While performing matrix addition and subtraction when both the operand of matrices must have same number of rows and columns.
Let us consider an example
a = [2 1 3; 4 5 6; 7 8 9];
b = [4 5 6; 1 2 3; 7 8 9];
c = a + b
a = [3 2 4; 4 5 6; 7 8 9];
b = [2 1 3; 3 2 1; 4 5 6];
d = a – b
If we run script file we get:
c= 6 6 9
5 7 9
14 16 18
d= 1 1 1
1 3 5
3 3 3
Division of (right, left) matrix:
If we want to perform the division of two matrices left (\) or right (/) division operation, when both the operand of matrices must have same number of rows and columns.
Now let us consider an example:
a = [1 2 3; 4 2 6; 7 5 2];
b = [3 5 6; 2 3 8; 5 7 2];
c = a / b
d = a \ b
If we run the above example we get output as:
c = -0.7916 0.1666 0.2083
1.0833 4.3333 0.9166
2.9583 4.6666 3.8333
d =
-3.27778 -1.05556 -4.86111
-0.11111 0.11111 -0.27778
3.05556 1.27778 4.30556
Transpose of matrix:
The transpose operation will be defined as switching of the rows and columns in a matrix. And it will be represented as a single quote (‘).
Let us consider example:
a = [11 12 13; 14 8 6; 27 8 9]
b = a’
It displayed has:
a = 11 12 13
14 8 6
27 8 9
b = 11 14 27
12 8 8
13 6 9