Navigation

Operators and Keywords

Function List:

C++ API

: repelems (x, r)

Construct a vector of repeated elements from x.

r is a 2xN integer matrix specifying which elements to repeat and how often to repeat each element. Entries in the first row, r(1,j), select an element to repeat. The corresponding entry in the second row, r(2,j), specifies the repeat count. If x is a matrix then the columns of x are imagined to be stacked on top of each other for purposes of the selection index. A row vector is always returned.

Conceptually the result is calculated as follows:

y = [];
for i = 1:columns (r)
 y = [y, x(r(1,i)*ones(1, r(2,i)))];
endfor

See also: repmat, cat.

Package: octave