Mercurial > hg > octave-nkf
diff doc/interpreter/numbers.txi @ 9158:48ee8c73ff38
info about ranges
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Wed, 29 Apr 2009 07:44:34 +0200 |
parents | 537a73861cb7 |
children | 923c7cb7f13f |
line wrap: on
line diff
--- 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.