Mercurial > hg > octave-nkf
annotate scripts/sparse/nonzeros.m @ 5915:b2e1be30c8e9 ss-2-9-7
[project @ 2006-07-28 18:08:56 by jwe]
author | jwe |
---|---|
date | Fri, 28 Jul 2006 18:08:56 +0000 |
parents | 57077d0ddc8e |
children | 2c85044aa63f |
rev | line source |
---|---|
5164 | 1 ## Copyright (C) 2004 Paul Kienzle |
2 ## | |
3 ## This program is free software and is in the public domain | |
4 | |
5 ## -*- texinfo -*- | |
6 ## @deftypefn {Function File} {} nonzeros (@var{s}) | |
7 ## Returns a vector of the non-zero values of the sparse matrix @var{s}. | |
8 ## @end deftypefn | |
9 | |
10 function t = nonzeros(s) | |
11 if issparse(s) | |
12 [i,j,t] = spfind(s); | |
13 else | |
14 [i,j,t] = find(s); | |
15 endif | |
16 endfunction | |
17 | |
18 %!assert(nonzeros([1,2;3,0]),[1;3;2]) | |
19 %!assert(nonzeros(sparse([1,2;3,0])),[1;3;2]) |