A single element of a vector, or a range of elements of a matrix, can be deleted by assigning a null value ([ ]). The resulting vector, or matrix will have smaller size. Examples are:
*Modified Deleted Matrix
*Modified Deleted Matrix
>> A=[8 9 2 4 5 2 1 7]
A =
8 9 2 4 5 2 1 7
>> A(3)=[] It will delete the third element
A =
8 9 4 5 2 1 7
>> A(1:4)=[] It will delete the first four elements
A =
2 1 7
* Deleting column elements Adding semicolon
>> Z=[5 9 8 6 5; 5 2 3 1 8; 4 5 6 3 1]
Z =
5 9 8 6 5
5 2 3 1 8
4 5 6 3 1
>> Z(:,[1,4])=[]
Z =
9 8 5
2 3 8
5 6 1
>> Z(3,:)=[]
Z =
9 8 5
2 3 8
>> Z(1,:)=[]
Z =
2 3 8
>> S=[1 2 3]
S =
1 2 3
>> S(4:6)=[4 6 9]
S =
1 2 3 4 6 9
>> S(8)=[45]
S =
1 2 3 4 6 9 0 45
>> T=[1 2 3; 7 8 9]
T =
1 2 3
7 8 9
* Adding elements to the matrix matlab
>> T(3,:)=[4 5 6]
T =
1 2 3
7 8 9
4 5 6