repelem
Repeats each element of an array a given number of times.
Category: Language Fundamentals > Matrices and Arrays
Syntax
B = repelem(v, n)
Repeats every element of the vector v n times.
B = repelem(v, counts)
Repeats element k of v counts(k) times.
B = repelem(A, r1, r2, ...)
For matrices, repeats along each dimension.
Description
Compare with repmat, which tiles the whole array: repmat([1 2], 1, 2) is 1 2 1 2 while repelem([1 2], 2) is 1 1 2 2. In a matrix repelem(A, 2, 3) turns each element into a block of 2 rows by 3 columns, a way to enlarge an image or a grid without interpolation.
Input arguments
v, A- Array of any type, including text and cell arrays.
n, counts, r1, ...- Repeat counts: a scalar, or a vector with one count per element.
Output arguments
B- Array in which each element is repeated in place.
Example
repelem([1 2 3], 2)
repelem([1 2 3], [1 2 3])
repelem([1 2; 3 4], 2, 2)
Output
ans = 1×6
1 1 2 2 3 3
ans = 1×6
1 2 2 3 3 3
ans = 4×4
1 1 2 2
1 1 2 2
3 3 4 4
3 3 4 4