- Back to Home »
- MAT LAB »
- How to delete row or column in Mat lab
Posted by : Unknown
Thursday, October 24, 2013
Deletion Of Row In Mat lab
if there is a given a matrix e.g
A=[1 2 3; 4 5 6; 7 8 9; 10 11 12]
if we want to remove fourth row then there is a specific command in MAT LAB with the help of which we can eliminate a row as well column :
we normally represent a vector A(row,column)
A(1:3,1:3) //1:3 represents First three row and same 1:3 represent first three column
ans =
1 2 3
4 5 6
7 8 9
A(1:3,1:3) //1:3 represents First three row and same 1:3 represent first three column
ans =
1 2 3
4 5 6
7 8 9
Another Method
If you want to remove a specific row in any matrix then use this command
A(2,:)=[] // if you want to remove nth row then use this command A(n,:)
A =
1 2 3
7 8 9
10 11 12
A(2,:)=[] // if you want to remove nth row then use this command A(n,:)
A =
1 2 3
7 8 9
10 11 12
Deletion Of Column In Mat lab
A=[1 2 3; 4 5 6; 7 8 9; 10 11 12]
Same here if we want to remove a column then same we use a same method. E.g if we want to remove a third column from a matrix then we use a command
A(1:3, 1:2) // 1:3 represents one to third row and same 1:2 represent first two column
ans =
1 2
4 5
7 8
Another Method
If you want to remove a specific column in any matrix then use this command
A(,:2)=[] // if you want to remove nth row then use this command A(,:n)
A =
1 2 3
7 8 9
10 11 12
A(,:2)=[] // if you want to remove nth row then use this command A(,:n)
A =
1 2 3
7 8 9
10 11 12