To repeat data in MATLAB, the repmat()
function can be used. The basic syntax for repmat()
function is as follows:
main.m20 chars2 lines
In the above syntax, A
is the array or matrix that you want to repeat, and m
and n
are the number of times you want to repeat A
along the rows and columns, respectively. The output B
is a matrix of size (size(A,1)*m, size(A,2)*n)
.
Here's an example to repeat a row vector [1 2 3]
three times horizontally and two times vertically:
main.m375 chars12 lines
In the above example, A
is repeated twice along the rows and three times along the columns. The output B
is a matrix of size 6x9
.
Note: If you want to repeat an array or matrix multiple times with the same size, you can also use the colon notation A(:)
to create a column vector, and then repeat it using repmat()
.
gistlibby LogSnag