repelem
Replicate array elements (per-element repetition).
Syntax
Section titled “Syntax”B = repelem(A, n)B = repelem(A, r1, r2, ...)Description
Section titled “Description”Replicates each element of A individually. With a scalar n, repeats every element n times along the first non-singleton dimension. With per-dimension counts r1, r2, ..., replicates each element r_k times along dimension k.
Different from repmat: repmat([1 2], 2) gives [1 2 1 2; 1 2 1 2] (block tiling); repelem([1 2], 2) gives [1 1 2 2] (per-element).
Examples
Section titled “Examples”repelem([1 2 3], 3) % [1 1 1 2 2 2 3 3 3]repelem([1 2; 3 4], 2, 3) % 4×6 with each entry repeated 2× rows, 3× cols