lettura simple

How to remove an element from an array in Octave

In this lesson I'll explain how to delete a value from an array in Octave.

I'll give you a practical example.

Create an array with five elements.

>> v=[1 2 3 4 5]
v =
1 2 3 4 5

To remove the third element from the array, type v(3)=[]

You have to indicate the position of the element to be removed between the round brackets.

>> v(3)=[]

This command deletes the element from the array.

When you assign a null value to an element of an array, the element is deleted from the array

Now the array has four elements.

>> v
v =
1 2 4 5

This way you can delete any element of an array, as long as the array is one dimensional.

Note. This command does not work if the array is two-dimensional (matrix) or higher (tensor).




Report a mistake or post a question




FacebookTwitterLinkedinLinkedin