repmat

Tiles copies of an array.

Category: Language Fundamentals > Matrices and Arrays

Syntax

B = repmat(A, n)

n-by-n tiling of A.

B = repmat(A, m, n, ...)

m copies down, n across, and so on.

B = repmat(A, sz)

Repeat counts given as a vector.

Description

The whole of A is copied as a block, so repmat([1 2], 2, 2) gives two rows of 1 2 1 2. It works on text and cell arrays: repmat('ab', 1, 3) is 'ababab' and repmat({0}, 1, 3) is a cell array of three zeros.

Since implicit expansion handles most arithmetic cases, repmat is now mainly needed for building arrays rather than for matching sizes.

Input arguments

A
Array of any type.
m, n, ...
How many copies along each dimension.

Output arguments

B
Array of size size(A) .* [m n ...].

Example

repmat([1 2], 2, 2)
repmat('ab', 1, 3)
repmat({0}, 1, 3)
Output
ans = 2×4

     1     2     1     2
     1     2     1     2
ans = 'ababab'
ans = 1×3 cell

    {[0]}    {[0]}    {[0]}

See also

repelem kron cat ones