changeset 6421:cac156381f81

[project @ 2007-03-20 17:39:19 by jwe]
author jwe
date Tue, 20 Mar 2007 17:39:19 +0000
parents e35658098bbc
children 9b982dd07654
files doc/ChangeLog doc/interpreter/sparse.txi
diffstat 2 files changed, 16 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- 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  <geordie.mcbain@aeromech.usyd.edu.au>
+
+	* interpreter/sparse.txi: Clarify sparse matrix creation example.
+
 2007-03-14  G. D. McBain  <geordie.mcbain@aeromech.usyd.edu.au>
 
 	* interpreter/sparse.txi: Fix typo.
--- 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