Repeat Copies of Array - MATLAB Repmat
Repeat Copies of Array - MATLAB Repmat
Syntax
B = repmat(A,n)
example
B = repmat(A,r)
example
B = repmat(A,r1,...,rN)
example
Description
B = repmat(A,n) returns an array containing n copies of A in the row and column dimensions.
The size of B is size(A)*n when A is a matrix.
example
B = repmat(A,r) specifies the repetition scheme with row vector r. For example, repmat(A,[2
3]) returns the same result as repmat(A,2,3).
example
Examples
collapse all
A =
100
0
0
0
200
0
0
0
300
B = repmat(A,2)
B =
100
0
0
100
0
0
example
0
200
0
0
200
0
0
0
300
0
0
300
100
0
0
100
0
0
0
200
0
0
200
0
0
0
300
0
0
300
A =
100
0
0
0
200
0
0
0
300
B = repmat(A,2,3)
B =
100
0
0
100
0
0
0
200
0
0
200
0
0
0
300
0
0
300
100
0
0
100
0
0
0
200
0
0
200
0
0
0
300
0
0
300
100
0
0
100
0
0
0
200
0
0
200
0
A =
1
3
2
4
B = repmat(A,[2 3 2])
0
0
300
0
0
300
B(:,:,1) =
1
3
1
3
2
4
2
4
1
3
1
3
2
4
2
4
1
3
1
3
2
4
2
4
2
4
2
4
1
3
1
3
2
4
2
4
1
3
1
3
2
4
2
4
B(:,:,2) =
1
3
1
3
B =
1
1
1
1
2
2
2
2
3
3
3
3
4
4
4
4
B =
1
2
3
1
2
3
1
2
3
1
2
3
A =
Age
___
Height
______
39
26
70
63
B =
Age
___
Height
______
Age_1
_____
Height_1
________
Age_2
_____
Height_2
________
39
26
39
26
70
63
70
63
39
26
39
26
70
63
70
63
39
26
39
26
70
63
70
63
repmat repeats the entries of the table and appends a number to the new variable names.
Input Arguments
collapse all
A Input array
Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical
| char | struct | table | cell
Complex Number Support: Yes
n Number of times to repeat input array in row and column dimensions
integer value
Number of times to repeat the input array in the row and column dimensions, specified as an integer value.
If n is 0 or negative, the result is an empty array.
Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64
r1,...,rN Repetition factors for each dimension (as separate arguments)
integer values
Repetition factors for each dimension, specified as separate arguments of integer values. If any repetition
Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64
r Vector of repetition factors for each dimension (as a row vector)
integer values
Vector of repetition factors for each dimension, specified as a row vector of integer values. If any value in r
is 0 or negative, the result is an empty array.
Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64
More About
expand all
Tips
To build block arrays by forming the tensor product of the input with an array of ones, use kron. For
example, to stack the row vector A = 1:3 four times vertically, you can use B = kron(A,ones(4,1)).
To create block arrays and perform a binary operation in a single pass, use bsxfun. In some cases,
bsxfun provides a simpler and more memory efficient solution. For example, to add the vectors A = 1:5
and B = (1:10)' to produce a 10-by-5 array, use bsxfun(@plus,A,B) instead of repmat(A,10,1) +
repmat(B,1,5).
When A is a scalar of a certain type, you can use other functions to get the same result as repmat.
repmat Syntax
Equivalent Alternative
repmat(single(inf),m,n)
inf(m,n,'single')
repmat(NaN,m,n)
repmat(int8(0),m,n)
repmat(uint32(1),m,n)
repmat(eps,m,n)
See Also
NaN(m,n)
zeros(m,n,'int8')
ones(m,n,'uint32')
eps(ones(m,n))