Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: construct diagonal block matrix
Date: Thu, 20 Aug 2009 21:29:20 +0000 (UTC)
Organization: Xoran Technologies
Lines: 8
Message-ID: <h6kf7g$hq4$1@fred.mathworks.com>
References: <h0uj19$i02$1@fred.mathworks.com> <h6kcbr$c3k$1@fred.mathworks.com> <h6kcvo$mkl$1@fred.mathworks.com> <h6ke5n$8sf$1@fred.mathworks.com> <h6kek8$9o4$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1250803760 18244 172.30.248.37 (20 Aug 2009 21:29:20 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 20 Aug 2009 21:29:20 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1440443
Xref: news.mathworks.com comp.soft-sys.matlab:564915


"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <h6kek8$9o4$1@fred.mathworks.com>...
> % Sorry make it:
> 
> A(:,2,:)=diag(M(:,2));
> A(:,1,:)=diag(M(:,1));
> A=reshape(A,size(M,1),[]);

Bruno- I think your original proposal would have to be faster than this for large data sets (but don't have time to check right now). Your original proposal works entirely in the sparse matrix domain, thus saving a lot of memory allocation ops, as compared to the above which constructs large full diagonal matrices. Unfortunately, your above proposal can't be modified to work in the sparse domain, because 3D arrays can't be represented as type sparse.