How to double the size of a matrix and propagate i

2019-01-20 14:36发布

问题:

suppose I have a matrix like this:

a = 
    1    2
    3    4

I want to double the size of matrix and create something like this:

aa = 
     1    1    2    2
     1    1    2    2
     3    3    4    4
     3    3    4    4

in this way, each element in the first matrix propagates to four elements in the bigger matrix.

a(i,j) == aa(2*i-1, 2*j-1)
       == aa(2*i  , 2*j-1)
       == aa(2*i-1, 2*j)
       == aa(2*i  , 2*j)

is there any predefined functions to do that?

definitely I can do that by two loops, but I want the easiest and cleanest way!

回答1:

use kron - Kronecker tensor product:

kron(a,ones(2))


ans =
 1     1     2     2
 1     1     2     2
 3     3     4     4
 3     3     4     4