changeset 6631:1b8daf8c0397

[project @ 2007-05-16 16:11:55 by jwe]
author jwe
date Wed, 16 May 2007 16:11:56 +0000
parents 0fcc8d65b571
children fc235391e58f
files scripts/ChangeLog scripts/general/ind2sub.m scripts/general/sub2ind.m src/ChangeLog src/ov.cc
diffstat 5 files changed, 59 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog	Wed May 16 15:32:09 2007 +0000
+++ b/scripts/ChangeLog	Wed May 16 16:11:56 2007 +0000
@@ -1,3 +1,7 @@
+2007-05-16  Søren Hauberg  <soren@hauberg.org>
+
+	* general/sub2ind.m, general/ind2sub.m: Doc fix.
+
 2007-05-16  John W. Eaton  <jwe@octave.org>
 
 	* general/logspace.m: Return second arg if fewer than two values
--- a/scripts/general/ind2sub.m	Wed May 16 15:32:09 2007 +0000
+++ b/scripts/general/ind2sub.m	Wed May 16 16:11:56 2007 +0000
@@ -20,6 +20,15 @@
 ## -*- texinfo -*-
 ## @deftypefn {Function File} {[@var{s1}, @var{s2}, @dots{}, @var{sN}] =} ind2sub (@var{dims}, @var{ind})
 ## Convert a linear index into subscripts.
+##
+## The following example shows how to convert the linear index @code{8}
+## in a 3-by-3 matrix into a subscript.
+##
+## @example
+## [r, c] = ind2sub ([3, 3], 8)
+## @result{} r =  2
+## c =  3
+## @end example
 ## @seealso{sub2ind}
 ## @end deftypefn
 
--- a/scripts/general/sub2ind.m	Wed May 16 15:32:09 2007 +0000
+++ b/scripts/general/sub2ind.m	Wed May 16 16:11:56 2007 +0000
@@ -21,6 +21,14 @@
 ## @deftypefn {Function File} {@var{ind} =} sub2ind (@var{dims}, @var{i}, @var{j})
 ## @deftypefnx {Function File} {@var{ind} =} sub2ind (@var{dims}, @var{s1}, @var{s2}, @dots{}, @var{sN})
 ## Convert subscripts into a linear index.
+##
+## The following example shows how to convert the two-dimensional
+## index @code{(2,3)} of a 3-by-3 matrix to a linear index.
+##
+## @example
+## linear_index = sub2ind ([3, 3], 2, 3)
+## @result{} 8
+## @end example
 ## @seealso{ind2sub}
 ## @end deftypefn
 
--- a/src/ChangeLog	Wed May 16 15:32:09 2007 +0000
+++ b/src/ChangeLog	Wed May 16 16:11:56 2007 +0000
@@ -1,3 +1,7 @@
+2007-05-16  Søren Hauberg  <soren@hauberg.org>
+
+	* ov.cc (Fsubsref, Fsubsasgn): Doc fix.
+
 2007-05-16  John W. Eaton  <jwe@octave.org>
 
 	* load-path.h (load_path::sys_path): New static data member.
--- a/src/ov.cc	Wed May 16 15:32:09 2007 +0000
+++ b/src/ov.cc	Wed May 16 16:11:56 2007 +0000
@@ -1951,6 +1951,25 @@
 are @samp{\"()\"}, @samp{\"@{@}\"}, and @samp{\".\"}.\n\
 The @samp{subs} field may be either @samp{\":\"} or a cell array\n\
 of index values.\n\
+\n\
+The following example shows how to extract the two first columns of\n\
+a matrix\n\
+\n\
+@example\n\
+val = magic(3)\n\
+     @result{} val = [ 8   1   6\n\
+                3   5   7\n\
+                4   9   2 ]\n\
+idx.type = \"()\";\n\
+idx.subs = @{\":\", 1:2@};\n\
+subsref(val, idx)\n\
+     @result{} [ 8   1 \n\
+          3   5 \n\
+          4   9 ]\n\
+@end example\n\
+\n\
+@noindent\n\
+Note that this is the same as writing @code{val(:,1:2)}.\n\
 @seealso{subsasgn, substruct}\n\
 @end deftypefn")
 {
@@ -1983,6 +2002,21 @@
 are @samp{\"()\"}, @samp{\"@{@}\"}, and @samp{\".\"}.\n\
 The @samp{subs} field may be either @samp{\":\"} or a cell array\n\
 of index values.\n\
+\n\
+The following example shows how to set the two first columns of a\n\
+3-by-3 matrix to zero.\n\
+\n\
+@example\n\
+val = magic(3);\n\
+idx.type = \"()\";\n\
+idx.subs = @{\":\", 1:2@};\n\
+subsasgn (val, idx, 0)\n\
+     @result{} [ 0   0   6\n\
+          0   0   7\n\
+          0   0   2 ]\n\
+@end example\n\
+\n\
+Note that this is the same as writing @code{val(:,1:2) = 0}.\n\
 @seealso{subsref, substruct}\n\
 @end deftypefn")
 {