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 20:47:04 +0000 (UTC)
Organization: FOGALE nanotech
Lines: 14
Message-ID: <h6kco8$7n5$1@fred.mathworks.com>
References: <h0uj19$i02$1@fred.mathworks.com> <h6kcbr$c3k$1@fred.mathworks.com>
Reply-To: "Bruno Luong" <b.luong@fogale.findmycountry>
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 1250801224 7909 172.30.248.37 (20 Aug 2009 20:47:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 20 Aug 2009 20:47:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 390839
Xref: news.mathworks.com comp.soft-sys.matlab:564896


M = [1 2; 3 4; 5 6];

I=repmat((1:size(M,1)),size(M,2),1);
J=1:numel(M);
Mt=M.';

% sparse
S=sparse(I(:),J(:),Mt(:))
% or full directly
A=accumarray([I(:),J(:)],Mt(:))

% Why should we bother with full matrix in algebra?

Bruno