Sophie

Sophie

distrib > Mageia > 7 > i586 > media > core-updates > by-pkgid > 641ebb3060c35990cc021d8f7aaf9aca > files > 442

octave-doc-5.1.0-7.1.mga7.noarch.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Ranges (GNU Octave (version 5.1.0))</title>

<meta name="description" content="Ranges (GNU Octave (version 5.1.0))">
<meta name="keywords" content="Ranges (GNU Octave (version 5.1.0))">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<link href="index.html#Top" rel="start" title="Top">
<link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Numeric-Data-Types.html#Numeric-Data-Types" rel="up" title="Numeric Data Types">
<link href="Single-Precision-Data-Types.html#Single-Precision-Data-Types" rel="next" title="Single Precision Data Types">
<link href="Empty-Matrices.html#Empty-Matrices" rel="prev" title="Empty Matrices">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smalllisp {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
ul.no-bullet {list-style: none}
-->
</style>
<link rel="stylesheet" type="text/css" href="octave.css">


</head>

<body lang="en">
<a name="Ranges"></a>
<div class="header">
<p>
Next: <a href="Single-Precision-Data-Types.html#Single-Precision-Data-Types" accesskey="n" rel="next">Single Precision Data Types</a>, Previous: <a href="Matrices.html#Matrices" accesskey="p" rel="prev">Matrices</a>, Up: <a href="Numeric-Data-Types.html#Numeric-Data-Types" accesskey="u" rel="up">Numeric Data Types</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<a name="Ranges-1"></a>
<h3 class="section">4.2 Ranges</h3>
<a name="index-range-expressions"></a>
<a name="index-expression_002c-range"></a>

<a name="index-_003a_002c-range-expressions"></a>

<p>A <em>range</em> is a convenient way to write a row vector with evenly
spaced elements.  A range expression is defined by the value of the first
element in the range, an optional value for the increment between
elements, and a maximum value which the elements of the range will not
exceed.  The base, increment, and limit are separated by colons (the
&lsquo;<samp>:</samp>&rsquo; character) and may contain any arithmetic expressions and
function calls.  If the increment is omitted, it is assumed to be 1.
For example, the range
</p>
<div class="example">
<pre class="example">1 : 5
</pre></div>

<p>defines the set of values <code>[ 1, 2, 3, 4, 5 ]</code>, and the range
</p>
<div class="example">
<pre class="example">1 : 3 : 5
</pre></div>

<p>defines the set of values <code>[ 1, 4 ]</code>.
</p>
<p>Although a range constant specifies a row vector, Octave does <em>not</em>
normally convert range constants to vectors unless it is necessary to do so.
This allows you to write a constant like <code>1 : 10000</code> without using
80,000 bytes of storage on a typical 32-bit workstation.
</p>
<p>A common example of when it does become necessary to convert ranges into
vectors occurs when they appear within a vector (i.e., inside square
brackets).  For instance, whereas
</p>
<div class="example">
<pre class="example">x = 0 : 0.1 : 1;
</pre></div>

<p>defines <var>x</var> to be a variable of type <code>range</code> and occupies 24
bytes of memory, the expression
</p>
<div class="example">
<pre class="example">y = [ 0 : 0.1 : 1];
</pre></div>

<p>defines <var>y</var> to be of type <code>matrix</code> and occupies 88 bytes of
memory.
</p>
<p>This space saving optimization may be disabled using the function
<em>disable_range</em>.
</p>
<a name="XREFdisable_005frange"></a><dl>
<dt><a name="index-disable_005frange"></a><em><var>val</var> =</em> <strong>disable_range</strong> <em>()</em></dt>
<dt><a name="index-disable_005frange-1"></a><em><var>old_val</var> =</em> <strong>disable_range</strong> <em>(<var>new_val</var>)</em></dt>
<dt><a name="index-disable_005frange-2"></a><em></em> <strong>disable_range</strong> <em>(<var>new_val</var>, &quot;local&quot;)</em></dt>
<dd><p>Query or set the internal variable that controls whether ranges are stored
in a special space-efficient format.
</p>
<p>The default value is true.  If this option is disabled Octave will store
ranges as full matrices.
</p>
<p>When called from inside a function with the <code>&quot;local&quot;</code> option, the
variable is changed locally for the function and any subroutines it calls.
The original variable value is restored when exiting the function.
</p>
<p><strong>See also:</strong> <a href="Basic-Usage.html#XREFdisable_005fdiagonal_005fmatrix">disable_diagonal_matrix</a>, <a href="Basic-Usage.html#XREFdisable_005fpermutation_005fmatrix">disable_permutation_matrix</a>.
</p></dd></dl>


<p>Note that the upper (or lower, if the increment is negative) bound on
the range is not always included in the set of values, and that ranges
defined by floating point values can produce surprising results because
Octave uses floating point arithmetic to compute the values in the
range.  If it is important to include the endpoints of a range and the
number of elements is known, you should use the <code>linspace</code> function
instead (see <a href="Special-Utility-Matrices.html#Special-Utility-Matrices">Special Utility Matrices</a>).
</p>
<p>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
</p>
<div class="example">
<pre class="example">a = 2*(1:1e7) - 1;
</pre></div>

<p>will produce the same result as <code>1:2:2e7-1</code>, but without ever forming a
vector with ten million elements.
</p>
<p>Using zero as an increment in the colon notation, as <code>1:0:1</code> 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 <code>ones</code>.  Note that because a range must be a
row vector, <code>ones (1, 10)</code> produces a range, while <code>ones (10, 1)</code>
does not.
</p>
<p>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.
</p>
<hr>
<div class="header">
<p>
Next: <a href="Single-Precision-Data-Types.html#Single-Precision-Data-Types" accesskey="n" rel="next">Single Precision Data Types</a>, Previous: <a href="Matrices.html#Matrices" accesskey="p" rel="prev">Matrices</a>, Up: <a href="Numeric-Data-Types.html#Numeric-Data-Types" accesskey="u" rel="up">Numeric Data Types</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>