Mercurial > hg > octave-lyh
diff scripts/sparse/nonzeros.m @ 5164:57077d0ddc8e
[project @ 2005-02-25 19:55:24 by jwe]
author | jwe |
---|---|
date | Fri, 25 Feb 2005 19:55:28 +0000 |
parents | |
children | 2c85044aa63f |
line wrap: on
line diff
new file mode 100644 --- /dev/null +++ b/scripts/sparse/nonzeros.m @@ -0,0 +1,19 @@ +## Copyright (C) 2004 Paul Kienzle +## +## This program is free software and is in the public domain + +## -*- texinfo -*- +## @deftypefn {Function File} {} nonzeros (@var{s}) +## Returns a vector of the non-zero values of the sparse matrix @var{s}. +## @end deftypefn + +function t = nonzeros(s) + if issparse(s) + [i,j,t] = spfind(s); + else + [i,j,t] = find(s); + endif +endfunction + +%!assert(nonzeros([1,2;3,0]),[1;3;2]) +%!assert(nonzeros(sparse([1,2;3,0])),[1;3;2])