Octave / Matlab: Extend a vector making it repeat itself?

Tom picture Tom · Mar 17, 2010 · Viewed 53k times · Source

Is there a way to extend a vector by making it repeat itself?

>v = [1 2];
>v10 = v x 5; %x represents some function. Something like "1 2" x 5 in perl

Then v10 would be:

>v10
     1 2 1 2 1 2 1 2 1 2

This should work for the general case, not just for [1 2]

Answer

Andrew Shepherd picture Andrew Shepherd · Mar 17, 2010

The function you're looking for is repmat().

v10 = repmat(v, 1, 5)