Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

make a matrix 'n' time bigger in matlab

I have a matrix like this

1 2 3 4 
2 3 4 5
3 4 5 6 

is there any function that makes rows n times and columns m times in matlab i mean for example for n=2 and m=3 the result be:

1 1 1 2 2 2 3 3 3 4 4 4 
1 1 1 2 2 2 3 3 3 4 4 4 
2 2 2 3 3 3 4 4 4 5 5 5 
2 2 2 3 3 3 4 4 4 5 5 5 
3 3 3 4 4 4 5 5 5 6 6 6 
3 3 3 4 4 4 5 5 5 6 6 6 

thanks

like image 556
Hossein Avatar asked Aug 24 '12 08:08

Hossein


1 Answers

You can use the kronecker product:

 A=[1 2 3 4;5 6 7 8;9 10 11 12];
 kron(A,ones(2,3))
ans =
     1     1     1     2     2     2     3     3     3     4     4     4
     1     1     1     2     2     2     3     3     3     4     4     4
     5     5     5     6     6     6     7     7     7     8     8     8
     5     5     5     6     6     6     7     7     7     8     8     8
     9     9     9    10    10    10    11    11    11    12    12    12
     9     9     9    10    10    10    11    11    11    12    12    12

For more information, you can look on wikipedia:

http://en.wikipedia.org/wiki/Kronecker_product

like image 62
Oli Avatar answered Nov 12 '22 13:11

Oli