# HG changeset patch # User jwe # Date 1174412359 0 # Node ID cac156381f81970b8a7e563057b4af2ab7f59e21 # Parent e35658098bbcfba29b17a2c8e3e66565f244b059 [project @ 2007-03-20 17:39:19 by jwe] diff -r e35658098bbc -r cac156381f81 doc/ChangeLog --- a/doc/ChangeLog Tue Mar 20 17:22:31 2007 +0000 +++ b/doc/ChangeLog Tue Mar 20 17:39:19 2007 +0000 @@ -1,3 +1,7 @@ +2007-03-20 G. D. McBain + + * interpreter/sparse.txi: Clarify sparse matrix creation example. + 2007-03-14 G. D. McBain * interpreter/sparse.txi: Fix typo. diff -r e35658098bbc -r cac156381f81 doc/interpreter/sparse.txi --- a/doc/interpreter/sparse.txi Tue Mar 20 17:22:31 2007 +0000 +++ b/doc/interpreter/sparse.txi Tue Mar 20 17:39:19 2007 +0000 @@ -206,30 +206,20 @@ vector of the same size containing the data to be stored. For example @example - function x = foo (r, j) - idx = randperm (r); - x = ([zeros(r-2,1); rand(2,1)])(idx); - endfunction - - ri = []; - ci = []; - d = []; - - for j=1:c - dtmp = foo (r, j); # Returns vector of length r with (:,j) values - idx = find (dtmp != 0.); - ri = [ri; idx]; - ci = [ci; j*ones(length(idx),1)]; - d = [d; dtmp(idx)]; - endfor - s = sparse (ri, ci, d, r, c); + ri = ci = d = []; + for j = 1:c + ri = [ri; randperm(r)(1:n)']; + ci = [ci; j*ones(n,1)]; + d = [d; rand(n,1)]; + endfor + s = sparse (ri, ci, d, r, c); @end example -creates an @var{r}-by-@var{c} sparse matrix with a random distribution of -2 elements per row. The elements of the vectors do not need to be sorted in -any particular order as Octave will sort them prior to storing the -data. However, pre-sorting the data will make the creation of the sparse -matrix faster. +creates an @var{r}-by-@var{c} sparse matrix with a random distribution +of @var{n} (<@var{r}) elements per column. The elements of the vectors +do not need to be sorted in any particular order as Octave will sort +them prior to storing the data. However, pre-sorting the data will +make the creation of the sparse matrix faster. The function @dfn{spconvert} takes a three or four column real matrix. The first two columns represent the row and column index respectively and