[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Building a multidimensional block diagonal matrix avoiding loops
From: |
PetrSt |
Subject: |
Re: Building a multidimensional block diagonal matrix avoiding loops |
Date: |
Tue, 16 Apr 2013 06:15:35 -0700 (PDT) |
Repair - the outer reshapes are abundant, so it could be rewritten as
% Block diagonal in third dim
a=l; b=m*n; c=n;
B = zeros([a,b,c]);
ida = repmat((1:a)',m*n,1);
idb = repmat((1:b),l,1);
idc = repmat((1:c),l*m,1);
idx = sub2ind([a,b,c],ida(:),idb(:),idc(:));
B(idx) = A(:)
% Block diagonal in all dims
a=l*n; b=m*n; c=n;
B = zeros([a,b,c]);
ida = rotdim(reshape(repmat((1:a)',1,m),l,m,n),1,[2,3]);
idb = repmat((1:b),l,1);
idc = repmat((1:c),l*m,1);
idx = sub2ind([a,b,c],ida(:),idb(:),idc(:));
B(idx) = A(:)
--
View this message in context:
http://octave.1599824.n4.nabble.com/Building-a-multidimensional-block-diagonal-matrix-avoiding-loops-tp4651767p4651920.html
Sent from the Octave - General mailing list archive at Nabble.com.