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

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

Leave a Comment