```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 12:13:02 +0000 (UTC)
Organization: FOGALE nanotech
Lines: 19
Message-ID: <gqnoke\$qu\$1@fred.mathworks.com>
References: <gqmlmt\$6tp\$1@fred.mathworks.com> <gqn6u7\$1s2\$1@fred.mathworks.com> <gqnf8d\$8kh\$1@fred.mathworks.com> <gqniod\$6ne\$1@fred.mathworks.com> <gqnjl1\$us\$1@fred.mathworks.com>
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 1238328782 862 172.30.248.37 (29 Mar 2009 12:13:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 29 Mar 2009 12:13:02 +0000 (UTC)
Xref: news.mathworks.com comp.soft-sys.matlab:528449

>
> Now how to get to one-liner solution (challenge proposed by Roger)?
>

A=[ 0 0 8 0 0 ;
1 4 0 0 2;
0 5 3 0 0;
7 0 0 6 0];
A=sparse(A)

d = [2 6]'; % To be removed

% One-liner solution !!!
A(A~=0) = subsref(subsasgn([],substruct('()',...
{setdiff((1:max(nonzeros(A))),d)}), ...
1:length(setdiff((1:max(nonzeros(A))),d))),...
substruct('()',{nonzeros(A)}))

% Bruno
```