repmat

repmat(A, n, m)

Construct a matrix by repeating the given matrix n times in dimension 1 and m times in dimension 2.

Examples

julia> foo = rand(1,1)
1x1 Array{Float64,2}:
 0.90576
julia> repmat(foo, 2, 3)
 0.90576    0.90576     0.90576
 0.90576    0.90576     0.90576

Using repmat for operations

julia> foo = ones(2,1);
julia> bar = rand(2,3);
julia> repmat(foo,1,3) + bar
 1.36425    1.69981     1.87673
 1.09371    1.95932     1.86284
  1. Repeat a matrix in both dimensions:

    julia> A = [1 2; 3 4];
    julia> repmat(A, 2, 3)
    4×6 Array{Int64,2}:
    1  2  1  2  1  2
    3  4  3  4  3  4
    1  2  1  2  1  2
    3  4  3  4  3  4

    This example repeats the matrix A twice along dimension 1 and three times along dimension 2, resulting in a larger matrix.

  2. Repeat a single-row matrix:

    julia> B = [10 20 30];
    julia> repmat(B, 1, 4)
    1×12 Array{Int64,2}:
    10  20  30  10  20  30  10  20  30  10  20  30

    The function can be used to repeat a single-row matrix n times in dimension 1.

  3. Repeat a single-column matrix:
    julia> C = [5; 6; 7];
    julia> repmat(C, 3, 1)
    9×1 Array{Int64,2}:
    5
    6
    7
    5
    6
    7
    5
    6
    7

    Similarly, you can repeat a single-column matrix m times in dimension 2.

Common mistake example:

julia> D = [1 2 3; 4 5 6];
julia> repmat(D, -1, 2)
ERROR: DomainError: Negative dimensions are not allowed in repmat.

In this example, the function is called with a negative value for the n parameter. repmat does not support negative dimensions. Make sure to provide valid positive dimensions for the repetition.

See Also

Ac_ldiv_B, Ac_ldiv_Bc, Ac_mul_B, Ac_mul_Bc, Ac_rdiv_B, Ac_rdiv_Bc, At_ldiv_B, At_ldiv_Bt, At_mul_B, At_mul_Bt, At_rdiv_B, At_rdiv_Bt, A_ldiv_Bc, A_ldiv_Bt, A_mul_B!, A_mul_Bc, A_mul_Bt, A_rdiv_Bc, A_rdiv_Bt, Bidiagonal, cond, conv2, det, diag, diagind, diagm, diff, eig, eigvals, eigvecs, expm, eye, full, inv, isdiag, ishermitian, isposdef, isposdef!, issym, istril, istriu, logabsdet, logdet, lyap, norm, qrfact, rank, repmat, rot180, rotl90, rotr90, sortrows, sqrtm, SymTridiagonal, trace, Tridiagonal, tril, tril!, triu, triu!, writedlm,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field
Details

Checking you are not a robot: