MATLAB: How to make a block diagonal matrix using blkdiag function for a N dimensions

MATLAB

I have a matrix A which can be converted using the
blkdiag(A,A);
for 2D and m
blkdiag(A,A,A);
for 3D but I want the user to input the dimension and based on that a block diagonal matrix has to be generated something like
blkdiag(A,A,A....An);
. I know we have to use loops but i cant wrap my head around the actual code, if anyone could help that'd be great !

Best Answer

C = repmat({A},n,1);
out = blkdiag(C{:});