Search code examples
arraysmatlabdimensions

Matlab repmat into long single dismension array?


I'm trying to take:

a = [1 2 3]  

and repeat it 5 times to get:

b = [1 2 3 1 2 3 1 2 3 1 2 3 1 2 3]  

but when I try:

b = repmat(a, 5, 1)  

instead I get:

 b =

 1     2     3
 1     2     3
 1     2     3
 1     2     3
 1     2     3

I could probably do it with a for loop but I'd like to do it correctly if possible. Any suggestions? Thanks in advance


Solution

  • Use the following code:

    b = repmat(a,1,5)
    

    The numbers '1' and '5' refer to the amount of rows and columns that you want to repeat the matrix a. The order is important.