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 20:38:23 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 34
Message-ID: <h6kc7v$4bg$1@fred.mathworks.com>
References: <h0uj19$i02$1@fred.mathworks.com> <h6kbdj$b2k$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 1250800703 4464 172.30.248.37 (20 Aug 2009 20:38:23 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 20 Aug 2009 20:38:23 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1941167
Xref: news.mathworks.com comp.soft-sys.matlab:564888


"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <h6kbdj$b2k$1@fred.mathworks.com>...
> "Tim Yang" <dlISCool@gmail.com> wrote in message <h0uj19$i02$1@fred.mathworks.com>...
> > I want to build a diagonal matrix such as
> > 
> > 1 2 0 0 0 0
> > 0 0 3 4 0 0 
> > 0 0 0 0 5 6 
> > 
> > with a given (arbitrary) matrix,   
> > 1 2
> > 3 4
> > 5 6
> > 
> > without using loops and cell arrays (conversion takes time)  blkdiag works with only parameters (a,b,c,d...) a,b,c,d... are row vectors.
> > suggestions?
> > 
> 
> spdiags(M,[0 1],3,4)
> 
> % Bruno

Bruno,

That gets close, but is not quite what the OP wants:

full(spdiags(M,[0 1],3,4))

returns

1     2     0     0
0     3     4     0
0     0     5     6

Danny