Path: news.mathworks.com!not-for-mail
From: "Bruno Luong" <b.luong@fogale.findmycountry>
Newsgroups: comp.soft-sys.matlab
Subject: Re: help with blkdiag()
Date: Fri, 12 Jun 2009 22:08:01 +0000 (UTC)
Organization: FOGALE nanotech
Lines: 8
Message-ID: <h0ujk1$p5o$1@fred.mathworks.com>
References: <h0uim1$pae$1@fred.mathworks.com>
Reply-To: "Bruno Luong" <b.luong@fogale.findmycountry>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1244844481 25784 172.30.248.38 (12 Jun 2009 22:08:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 12 Jun 2009 22:08:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 390839
Xref: news.mathworks.com comp.soft-sys.matlab:547060


A = [1 2 3 4 5;
  6 7 8 9 10;
 11 12 13 14 15;
 16 17 18 19 20 ];

I = repmat((1:size(A,1)), size(A,2),1);
J = 1:numel(A);
B = accumarray([I(:) J(:)],reshape(A.',[],1)) % sparse is even better