# HG changeset patch # User Jaroslav Hajek # Date 1240983874 -7200 # Node ID 48ee8c73ff386dd3f5e500b31c0477bf0b51fcbf # Parent fce7315c1eee9b53046b36b3b3fdf7c751e5225f info about ranges diff -r fce7315c1eee -r 48ee8c73ff38 doc/ChangeLog --- a/doc/ChangeLog Tue Apr 28 19:45:40 2009 -0400 +++ b/doc/ChangeLog Wed Apr 29 07:44:34 2009 +0200 @@ -1,3 +1,7 @@ +2009-04-29 Jaroslav Hajek + + * interpreter/numbers.txi: Update info on ranges. + 2009-04-26 Rik * interpreter/arith.txi: Update section 17.3 (Trigonometry) of arith.txi diff -r fce7315c1eee -r 48ee8c73ff38 doc/interpreter/numbers.txi --- a/doc/interpreter/numbers.txi Tue Apr 28 19:45:40 2009 -0400 +++ b/doc/interpreter/numbers.txi Wed Apr 29 07:44:34 2009 +0200 @@ -403,6 +403,25 @@ number of elements is known, you should use the @code{linspace} function instead (@pxref{Special Utility Matrices}). +When adding a scalar to a range, subtracting a scalar from it (or subtracting a +range from a scalar) and multiplying by scalar, Octave will attempt to avoid +unpacking the range and keep the result as a range, too, if it can determine +that it is safe to do so. For instance, doing + +@example +a = 2*(1:1e7) - 1; +@end example + +will produce the same result as @samp{1:2:2e7-1}, but without ever forming a +vector with ten million elements. + +Using zero as an increment in the colon notation, as @samp{1:0:1} is not +allowed, because a division by zero would occur in determining the number of +range elements. However, ranges with zero increment (i.e. all elements equal) +are useful, especially in indexing, and Octave allows them to be constructed +using the built-in function @dfn{ones}. Note that because a range must be a row +vector, @samp{ones (1, 10)} produces a range, while @samp{ones (10, 1)} does not. + When Octave parses a range expression, it examines the elements of the expression to determine whether they are all constants. If they are, it replaces the range expression with a single range constant.