zeros

zeros(m)

zeros(m, n)

zeros(m, n, p, ...)

zeros([m])

zeros([m, n])

zeros([m, n, p, ...])

Try it yourself:


Create zero-filled arrays and matrices

zeros creates an array or matrix whose entries are all zero. It is a convenient starting point for accumulators, masks, coefficient tables, and linear-algebra calculations where every value will later be filled or updated.

Examples and alternatives

Use a single dimension to create a zero vector, or multiple dimensions to create a rectangular matrix. Check the result with size before combining it with another matrix. ones creates the corresponding all-one matrix, while identity creates a square matrix with ones only on its diagonal.

Practical use

A zero matrix can represent an initial sum of matrix contributions. Build or update compatible values with add, and use matrixFromFunction when entries follow a known index-based rule from the start. Zero initialization should not be used as a missing-data marker unless zero is impossible in the domain.

Input caveats

Dimensions should be non-negative integers. Large dimensions consume memory quickly, so create only the shape required. A zero matrix has numeric zero entries; it is not an empty collection. Use count when you need the number of entries rather than a matrix of them.

All functions