Skip to content

repelem

Replicate array elements (per-element repetition).

B = repelem(A, n)
B = repelem(A, r1, r2, ...)

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).

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
  • repmat — Tile an array by replicating its contents.
  • reshape — Reshape an array without changing its data.