2

Possible Duplicate:
Element-wise array replication in Matlab

I have a m x 1 vector that I would like to repeat n times to create a (m*n)x1 vector. If I use repmat, I get something like

>> V = [a;b;c];
>> repmat(V,2,1) % n = 2, m = 3
a
b
c
a
b
c

What would be a one-line (and hopefully fast) way of getting the vector

[a;a;a;b;b;b;c;c;c]

for arbitrary n and m?

Community
  • 1
  • 1
foglerit
  • 7,792
  • 8
  • 44
  • 64

1 Answers1

7
V=[ 1;2;3];
reshape(repmat(V',3,1),[],1)

ans =

     1
     1
     1
     2
     2
     2
     3
     3
     3
Oli
  • 15,935
  • 7
  • 50
  • 66