Johnny5
Johnny5

Reputation: 6882

Repeat values in a matrix

Imagine a matrix :

a =

     4
     2
     8
     9

I need to repeat it n times. If n = 3, the result is :

a =

     4
     4
     4
     2
     2
     2
     8
     8
     8
     9
     9
     9

Upvotes: 0

Views: 578

Answers (2)

andNoob
andNoob

Reputation: 159

try using the kron function, newMatrix = kron(a,ones(1,4))

Upvotes: 0

H.Muster
H.Muster

Reputation: 9317

You can try:

n = 3; 
reshape(repmat(a', n, 1), numel(a)*n, 1)

Upvotes: 7

Related Questions