Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Return empty sparse from a mex file
Date: Mon, 26 Oct 2009 10:02:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 18
Message-ID: <hc3s2q$fbd$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1256551322 15725 172.30.248.38 (26 Oct 2009 10:02:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 26 Oct 2009 10:02:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1935580
Xref: news.mathworks.com comp.soft-sys.matlab:580029


Hello!

I'm trying to assemble and return a sparse matrix in a mex-function. At the end of the function, I try to correct for the actual number of non-zero entries in the following way (where Btu = mxGetPr(plhs[0]);):

"nbytes = actual_number_of_nonzeros*sizeof(*Btu);
 newptr = mxRealloc(Btu,nbytes);     
 mxSetPr(plhs[0], newptr); 
        
 nbytes = actual_number_of_nonzeros*sizeof(*ir);
 newptr = mxRealloc(ir, nbytes);
 mxSetIr(plhs[0], newptr);"

To test my function I have tried , the, excellent, spok-function, see http://www.mathworks.com/matlabcentral/fileexchange/20186-spok-checks-if-a-matlab-sparse-matrix-is-ok, which gives an ok except when the output is empty, i.e. nnz = 0. spok then returns the error message "double, but with no values present". The resulting matrix still seem to work fine but it's a little disturbing to have an error which I don't understand.

My question is thus: What should my function return if actual_number_of_nonzeros = 0?

Best regards
Arne