Thread Subject: A problem about sparse matrix

Subject: A problem about sparse matrix

From: zedong

Date: 1 Jan, 2009 12:39:02

Message: 1 of 2

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

Subject: A problem about sparse matrix

From: Matt

Date: 1 Jan, 2009 14:30:04

Message: 2 of 2

"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.';

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com