Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: A problem about  sparse matrix
Date: Thu, 1 Jan 2009 14:30:04 +0000 (UTC)
Organization: Xoran Technologies
Lines: 19
Message-ID: <gjik1c$nn9$1@fred.mathworks.com>
References: <gjidh6$e25$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 1230820204 24297 172.30.248.37 (1 Jan 2009 14:30:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 1 Jan 2009 14:30:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1440443
Xref: news.mathworks.com comp.soft-sys.matlab:509414


"zedong 
" <zdongwu@gmail.com> wrote in message <gjidh6$e25$1@fred.mathworks.com>...
> I now have a matrix  It's a matrix I want to do the following thing:
> A is a sparse  matrix.for example n by n
> rowcolumindex is an vector which store some index of A.My code is like this:
> A(rowcolumindex,:)=0;
> A(rowcolumindex,rowcolumindex)=speye(length(rowcolumindex));%You can understand I want to set the rows rowcolumindex be a eye matrix.
> But I find it's no efficiency.Because after the first row code that A(rowcolumindex,:) now become a full matrix,I think. Am I right?Any efficiency implementation


I would prefer to do it this way:

complement=1:n; 
complement(rowcolumnindex)=[];

Anew=speye(n);
Anew(:,complement)=A(complement,:).'; %filling columns of sparse matrices is faster.
Anew=Anew.';