How to double the size of a matrix and propagate its elements in Matlab?

怎甘沉沦 提交于 2019-11-27 08:19:08

问题


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


来源:https://stackoverflow.com/questions/14576007/how-to-double-the-size-of-a-matrix-and-propagate-its-elements-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!