# How to create a null matrix in Matlab and Octave

To create a null matrix in Matlab and Octave use the function zeros()

zeros(a,b)

The zeros() function has two parameters

• The first parameter is the number of rows in the matrix.
• The second parameter is the number of columns in the matrix.

What is a null matrix? A null matrix (or zero matrix) is a square or rectangular matrix with all elements are zero. An example of a null square matrix with three rows and three columns. $$M = \begin{pmatrix} 0 & 0 & 0 \\ 0 & 0 & 0 \\ 0 & 0 & 0 \end{pmatrix}$$

## Examples

Example 1

Create a 2x3 null matrix with two rows and three columns

>> zeros(2,3)
ans =
0 0 0
0 0 0

The result is a null rectangular matrix where all elements are zero.

Example 2

Create a 3x3 null matrix with three rows and three columns

>> zeros(3,3)
ans =
0 0 0
0 0 0
0 0 0

The result is a null square matrix where all elements are zero.

https://how.okpedia.org/en/matlab/how-to-create-a-null-matrix-in-matlab-and-octave

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

Matrix in Matlab/Octave