Path: news.mathworks.com!not-for-mail
From: "Bruno Luong" <b.luong@fogale.findmycountry>
Newsgroups: comp.soft-sys.matlab
Subject: Re: construct diagonal block matrix
Date: Thu, 20 Aug 2009 21:28:04 +0000 (UTC)
Organization: FOGALE nanotech
Lines: 15
Message-ID: <h6kf54$d7v$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> <h6kepr$knh$1@fred.mathworks.com>
Reply-To: "Bruno Luong" <b.luong@fogale.findmycountry>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1250803684 13567 172.30.248.35 (20 Aug 2009 21:28:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 20 Aug 2009 21:28:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 390839
Xref: news.mathworks.com comp.soft-sys.matlab:564914


"Danny Klein" <djklein.dont.include.this.part@gmail.com> wrote in message <h6kepr$knh$1@fred.mathworks.com>...
> "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <h6ke5n$8sf$1@fred.mathworks.com>...
> > This should be pretty fast:
> > 
> > A(:,1,:)=diag(M(:,1));
> > A(:,2,:)=diag(M(:,2));
> > A=reshape(A,size(M,1),[])
> > 
> > % Bruno
> 
> Looks like an improvement to the solution I proposed, unfortunately it is not as fast as Matt's approach:

Danny please reverse the two DIAG lines (avoid reallocation, which is a big drawback).

Bruno