5164
|
1 ## Copyright (C) 2004 David Bateman & Andy Adler |
|
2 ## |
|
3 ## This program is free software; you can redistribute it and/or modify |
|
4 ## it under the terms of the GNU General Public License as published by |
|
5 ## the Free Software Foundation; either version 2 of the License, or |
|
6 ## (at your option) any later version. |
|
7 ## |
|
8 ## This program is distributed in the hope that it will be useful, |
|
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 ## GNU General Public License for more details. |
|
12 ## |
|
13 ## You should have received a copy of the GNU General Public License |
|
14 ## along with this program; if not, write to the Free Software |
5307
|
15 ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
16 ## 02110-1301 USA |
5164
|
17 |
|
18 ## -*- texinfo -*- |
|
19 ## @deftypefn {Function File} {@var{y} =} spones (@var{x}) |
|
20 ## Replace the non-zero entries of @var{x} with ones. This creates a |
|
21 ## sparse matrix with the same structure as @var{x}. |
|
22 ## @end deftypefn |
|
23 |
|
24 function s = spones(s) |
|
25 if issparse(s) |
|
26 [i,j,v,m,n] = spfind(s); |
|
27 else |
|
28 [i,j,v] = find(s); |
|
29 [m,n] = size(s); |
|
30 end |
|
31 s = sparse(i,j,1,m,n); |
|
32 endfunction |
|
33 |
|
34 %!assert(issparse(spones([1,2;3,0]))) |
|
35 %!assert(spones([1,2;3,0]),sparse([1,1;1,0])) |
|
36 %!assert(spones(sparse([1,2;3,0])),sparse([1,1;1,0])) |