MATLAB: Merge repetitive matrices to Final one

MATLABmatrix arraymatrix manipulation

Hi, I want to create a single matrix(M) whose elements h1 and h2 are matrices of dimension 3 by themselves. The dimension of matrix (M) changes with the repetation of h1 and h2. and are conjugate transpose of h1 and h2. Empty spaces in the matrix are all 0's. Final goal is to find the eigensystem of M, and creating Matrix(M) will solve it. Will you please help me with the proper direction to approach the problem

Best Answer

%create test data
h1 = complex(rand(3,3), rand(3,3));
h2 = complex(rand(3,3), rand(3,3));
%do the work
NR = 10; %number of repetitions of h1
h1blks = repmat({h1}, 1, N);
h2blks = repmat({h2}, 1, N-1);
h2tblks = repmat({h2'}, 1, N-1);
M2 = [zeros(3, NR*3);
blkdiag(h2blks{:}), zeros(NR*3-3,3)];
M2t = [zeros(NR*3-3,3), blkdiag(h2tblks{:});
zeros(3, NR*3) ];
M = blkdiag(h1blks{:}) + M2 + M2t;