MATLAB: How to ‘stretch’ a matrix using a loop

loopreshapestretch matrix

Hi,
I have a 252×252 distance matrix. Now I need to reshape this matrix into a 3528×3528 matrix: so rows and columns times 14. I want the first 14 rows and columns, so a matrix of 1:14,1:14, filled with the first cell in the old matrix.
So Dnew 1:14,1:14 = Dold 1,1 Dnew 15:28,1:14 = Dold 2,1 D new 1:14,15:28 = Dold 1,2
How do I program this using a loop? Since I need to repeat it for every 1:14,1:14 matrix within my 3528×3528 matrix.
Thanks

Best Answer

R2015a or later: use repelem:
repelem(M,14,14)
Earlier versions: use kron:
kron(M,ones(14))
Related Question