help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Building a multidimensional block diagonal matrix avoiding loops


From: Jose
Subject: Re: Building a multidimensional block diagonal matrix avoiding loops
Date: Mon, 15 Apr 2013 14:36:22 +0300
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130308 Thunderbird/17.0.4

Hello.

On 04/12/2013 09:47 PM, c. wrote:

On 12 Apr 2013, at 20:43, Jose <address@hidden> wrote:

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

I think the function "kron" could be of help with your problem.

Thanks for the suggestion, but the "kron" function does not seem to work with multidimensional matrices. So I still don't see how I could avoid the loop.

BR
J.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]