Mercurial > hg > octave-lojdl
changeset 9158:48ee8c73ff38
info about ranges
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Wed, 29 Apr 2009 07:44:34 +0200 |
parents | fce7315c1eee |
children | c07cbffb82e3 |
files | doc/ChangeLog doc/interpreter/numbers.txi |
diffstat | 2 files changed, 23 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,7 @@ +2009-04-29 Jaroslav Hajek <highegg@gmail.com> + + * interpreter/numbers.txi: Update info on ranges. + 2009-04-26 Rik <rdrider0-list@yahoo.com> * interpreter/arith.txi: Update section 17.3 (Trigonometry) of arith.txi
--- a/doc/interpreter/numbers.txi +++ b/doc/interpreter/numbers.txi @@ -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.