# How to delete a row of the matrix in Matlab and Octave

To remove a row of a matrix in Matlab / Octave type the command

**M(n,:)=[ ]**

- M is the name of the matrix
- n is the number of the row to be deleted
- [ ] is an empty vector

## Examples

**Example 1**

Define a 4x2 matrix

>> M = [ 1 2 ; 3 4 ; 5 6 ; 7 8 ]

M =

1 2

3 4

5 6

7 8

To delete the first row from the matrix type **M(1,:)=[ ]
**

>> M(1,:)=[ ]

M =

3 4

5 6

7 8

The first row is deleted from the matrix

The result is a 3x2 matrix

**Example 1**

Define a 3x3 matrix

>> M = [ 1 2 3 ; 4 5 6 ; 7 8 9 ]

M =

1 2 3

4 5 6

7 8 9

To remove the second row of the matrix type **M(2,:)=[ ]**

>> M(:,2)=[]

M =

1 2 3

7 8 9

This command deletes the second row of the matrix

The result is a 2x3 matrix.

https://how.okpedia.org/en/matlab/how-to-delete-a-row-of-the-matrix-in-matlab-and-octave

**Report us an error or send a suggestion to improve this page**