Path: news.mathworks.com!not-for-mail
From: "Bruno Luong" <b.luong@fogale.findmycountry>
Newsgroups: comp.soft-sys.matlab
Subject: Re: FAST algorithm to jenga matrix?
Date: Sun, 29 Mar 2009 10:32:45 +0000 (UTC)
Organization: FOGALE nanotech
Lines: 8
Message-ID: <gqniod$6ne$1@fred.mathworks.com>
References: <gqmlmt$6tp$1@fred.mathworks.com> <gqn6u7$1s2$1@fred.mathworks.com> <gqnf8d$8kh$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 1238322765 6894 172.30.248.37 (29 Mar 2009 10:32:45 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 29 Mar 2009 10:32:45 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 390839
Xref: news.mathworks.com comp.soft-sys.matlab:528436

Here is a four-liner solution. I could merge the 2nd and 3rd lines but it does not bring any advantage beside having less lines:

[I J Val]=find(A);
u = unique(Val); % 1:n
[f NewVal]=ismember(u,setdiff(u,d));
B=sparse(I,J,NewVal(Val),size(A,1),size(A,2));

% Bruno