repmat: Replicate matrices.

Description Usage Arguments Value See Also Examples

Description

A simple wrapper for matrix that emulates repmat from Matlab. The function behaves similar to matrix function when a single scalar is specified - it multiplies that scalar to fill out a matrix specified by nrow and ncol arguments. The repmat function takes the whole matrix and treats it as if it were a scalar, and replicates it as many times as needed to fill out a new matrix specified by nrow and ncol arguments.

Usage

1
repmat(mat, nrow = 1, ncol = 1)

Arguments

mat

A matrix.

nrow

A scalar that determines how many times mat will be replicated and added as new rows, each of the size of mat. Default value is 1.

ncol

A scalar that determines how many times mat will be replicated and added as new columns, each of the size of mat. Default value is 1.

Value

A matrix where mat is copied ncol x nrow times and added as new columns as specified in ncol and new rows as specified in nrow.

See Also

matrix

Examples

1
2
3
4
5
# create a simple matrix
mat <- matrix(1:4, 2, 2)

# now we take it as a block and replicate it to fill a 2x3 block matrix 
repmat(mat, 2, 3)

hstojic/hfunk documentation built on May 17, 2019, 6:16 p.m.