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{s} =} spalloc (@var{r}, @var{c}, @var{nz}) |
|
20 ## Returns an empty sparse matrix of size @var{r}-by-@var{c}. As Octave |
|
21 ## resizes sparse matrices at the first opportunity, so that no additional |
|
22 ## space is needed, the argument @var{nz} is ignored. This function is |
|
23 ## provided only for compatiability reasons. |
|
24 ## |
|
25 ## It should be noted that this means that code like |
|
26 ## |
|
27 ## @example |
|
28 ## k = 5; |
|
29 ## nz = r * k; |
|
30 ## s = spalloc (r, c, nz) |
|
31 ## for j = 1:c |
|
32 ## idx = randperm (r); |
|
33 ## s (:, j) = [zeros(r - k, 1); rand(k, 1)] (idx); |
|
34 ## endfor |
|
35 ## @end example |
|
36 ## |
|
37 ## will reallocate memory at each step. It is therefore vitally important |
|
38 ## that code like this is vectorized as much as possible. |
|
39 ## @end deftypefn |
|
40 ## @seealso{sparse, nzmax} |
|
41 |
|
42 function s = spalloc (r, c, nz) |
|
43 s = sparse (r, c); |
|
44 endfunction |