How to delete some elements from a vector in Matlab and Octave
To delete an element from a vector, assign a null value [ ] to the element
v(n)=[ ]
The parameter n is the position of the element in the index of the vector.
To delete some continuous elements in the index write this comand
v(x:y)=[ ]
The x parameter is the position of the first element of the range, the y parameter is the position of the last element of the range.
To delete all elements of a vector, assign a null value [ ] to the vector
v=[ ]
This command deletes the elements present in the vector
Examples
Define a vector
>> v=['a'; 'b'; 'c'; 'd'; 'e'; 'f';'g']
v =
a
b
c
d
e
f
g
The vector has seven elements
To delete the sixth element, type
v(6)=[ ]
Now the vector has six elements
v =
b
c
d
e
g
To delete the group of elements between the second and fourth element type
>> v(4:6)=[ ]
Now the vector has 3 elements.
v =
a
b
c
To delete all elements of the vector type
>> v=[ ]
This command deletes all elements in the vector.