How do I convert a 2X2 matrix to 4X4 matrix in MATLAB?

后端 未结 7 986
無奈伤痛
無奈伤痛 2020-12-03 23:26

I need some help in converting a 2X2 matrix to a 4X4 matrix in the following manner:

A = [2 6;
     8 4]

should become:

B =         


        
7条回答
  •  醉梦人生
    2020-12-04 00:11

    In newer versions of MATLAB (R2015a and later) the easiest way to do this is using the repelem function:

    B = repelem(A, 2, 2);
    

    For older versions, a short alternative to the other (largely) indexing-based solutions is to use the functions kron and ones:

    >> A = [2 6; 8 4];
    >> B = kron(A, ones(2))
    
    B =
    
         2     2     6     6
         2     2     6     6
         8     8     4     4
         8     8     4     4
    

提交回复
热议问题