repmat#
Purpose#
Tiles (repeats) a matrix to create a larger matrix.
Format#
- B = repmat(A, m, n)#
- Parameters:
A (RxC matrix) – matrix to tile.
m (scalar) – number of times to tile vertically.
n (scalar) – number of times to tile horizontally.
- Returns:
B ((R*m)x(C*n) matrix) – containing m x n copies of A.
Examples#
Tile a matrix into a 2x3 grid#
A = { 1 2,
3 4 };
B = repmat(A, 2, 3);
After the above code, B will equal:
1 2 1 2 1 2
3 4 3 4 3 4
1 2 1 2 1 2
3 4 3 4 3 4
Repeat a column vector across columns#
v = { 10, 20, 30 };
B = repmat(v, 1, 4);
After the above code, B will equal:
10 10 10 10
20 20 20 20
30 30 30 30
Stack a row vector vertically#
r = { 1 2 3 };
B = repmat(r, 3, 1);
After the above code, B will equal:
1 2 3
1 2 3
1 2 3
Remarks#
Added in version 26.0.1.
repmat() uses the Kronecker product to tile the input matrix. It is equivalent to:
B = ones(m, n) .*. A;