Hello.
I need to create a multidimensional block diagonal matrix from another
multidimensional matrix. Let me put a simplified example.
I have A
A(:,:,1)=[1 2;3 4];
A(:,:,2)=[5 6;7 8];
from which I want to create B
B(:,:,1)=[1 2 0 0;3 4 0 0];
B(:,:,2)=[0 0 5 6;0 0 7 8];
so the expansion occurs in diagonal blocks in the second dimension.
If I had the problem with a 2D matrix, I could combine mat2cell and blkdiag to
create the new expanded matrix. But having a multidimensional matrix I cannot
see a way to avoid a loop, such as for example:
[l,m,n]=size(A);
for k=1:n
B(:,:,k)=[zeros(l,m*(k-1)) A(:,:,k) zeros(l,m*(n-k))];
endfor
Anybody has any idea about how to make this avoiding the loop?
BR
Jose