Repeat copies of array
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(NaN,m,n) | NaN(m,n) |
repmat(single(inf),m,n) | inf(m,n,'single') |
repmat(int8(0),m,n) | zeros(m,n,'int8') |
repmat(uint32(1),m,n) | ones(m,n,'uint32') |
repmat(eps,m,n) | eps(ones(m,n)) |