help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: nnz and char


From: David Bateman
Subject: Re: nnz and char
Date: Tue, 31 Jan 2006 15:21:02 +0100
User-agent: Mozilla Thunderbird 0.8 (X11/20040923)

John W. Eaton wrote:

On 30-Jan-2006, Andrew Funk wrote:

| I have some code that calls nnz on the result of a call to char, e.g.
|
| >> m=char(magic(3)+64)
|
| m =
|
| HAF
| CEG
| DIB
|
| >> nnz(m)
|
| ans =
|
|      9
|
| This works in Matlab but in Octave I get an error:
|
| octave:27> nnz(m)
| error: nnz: wrong type argument `sq_string'
|
| I'm wondering if this is considered a bug that would eventually be fixed
| in Octave, or should I be thinking of a way to change the code to avoid
| this situation?  (In the actual code there can be zeros so it makes
| sense to be calling nnz, I just created a toy example above).

Here's a patch, relative to the current CVS sources.

Thanks,

jwe

This patch is not quite right. The problem is that there are two methods in Sparse<T> for the number of non-zero elements. These are "nnz" and "nonzero". "nnz" returns the size of data and ridx, while nonzero returns "cidx[ncol]"... For matlab compatiablity for sparse matrices, Fnnz should return "cidx[ncol]" rather than the size of ridx and data, which is why the old Fnnz in sparse.cc used the "nonzero" method of Sparse<T>..

Regards

--
David Bateman                                address@hidden
Motorola Labs - Paris +33 1 69 35 48 04 (Ph) Parc Les Algorithmes, Commune de St Aubin +33 6 72 01 06 33 (Mob) 91193 Gif-Sur-Yvette FRANCE +33 1 69 35 77 01 (Fax) The information contained in this communication has been classified as: [x] General Business Information [ ] Motorola Internal Use Only [ ] Motorola Confidential Proprietary



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]