Path: news.mathworks.com!not-for-mail
From: "Tim Davis" <davis@cise.ufl.edu>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Is there any mex implementation of sparse matrix that I can add only one element to the matrix?
Date: Tue, 6 Jan 2009 21:44:02 +0000 (UTC)
Organization: University of Florida
Lines: 20
Message-ID: <gk0jb2$h6p$1@fred.mathworks.com>
References: <gjph5h$a0o$1@fred.mathworks.com>
Reply-To: "Tim Davis" <davis@cise.ufl.edu>
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 1231278242 17625 172.30.248.37 (6 Jan 2009 21:44:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 6 Jan 2009 21:44:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 45902
Xref: news.mathworks.com comp.soft-sys.matlab:510122


"zedong 
" <zdongwu@gmail.com> wrote in message <gjph5h$a0o$1@fred.mathworks.com>...
> Is there any mex implementation of sparse matrix that I can add only one element to the matrix?
>  I am working on finite element method.I want to use sparse matrix.But mex file has no function for sparse matrix for add only one element.
> for example,I want to do the following thing in c programming:
> a is now a sparse matrix of 100000 by 100000(for example)
> elem is the index matrix of 10000 by 3;
> for(i=0;i<10000;i++)
> {
>         for(j=0;j<3;j++)
>         for(k=0;k<3;k++)
>        {
>               jdex=elem(i,j);
>               kdex=elem(i,k);
>                a(jdex,kdex)=a(jdex,kdex)+f( )  /*f is some function to compute the value needed to be added*/
>        }
> }
> Do you know any use friendly code about sparse matrix in mex file that contain the interface  function as above?Thank you very much

Download SuiteSparse, and take a look at the functions in CSparse (for creating a triplet matrix and converting it to compressed-sparse-column).  Or see the same functions in CHOLMOD, which do the same thing as "sparse" (just a different algorithm; often faster than the built-in "sparse").  Those functions do what John mentioned ... they build the matrix as a list of triplets and then convert them all at once to a compress-sparse-column matrix.