/usr/share/doc/octave-htmldoc/interpreter/Index-Expressions.html is in octave-htmldoc 3.8.2-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
<head>
<title>GNU Octave: Index Expressions</title>
<meta name="description" content="GNU Octave: Index Expressions">
<meta name="keywords" content="GNU Octave: Index Expressions">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<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="Expressions.html#Expressions" rel="up" title="Expressions">
<link href="Advanced-Indexing.html#Advanced-Indexing" rel="next" title="Advanced Indexing">
<link href="Expressions.html#Expressions" rel="prev" title="Expressions">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.indentedblock {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
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.nocodebreak {white-space:nowrap}
span.nolinebreak {white-space:nowrap}
span.roman {font-family:serif; font-weight:normal}
span.sansserif {font-family:sans-serif; font-weight:normal}
ul.no-bullet {list-style: none}
-->
</style>
</head>
<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
<a name="Index-Expressions"></a>
<div class="header">
<p>
Next: <a href="Calling-Functions.html#Calling-Functions" accesskey="n" rel="next">Calling Functions</a>, Up: <a href="Expressions.html#Expressions" accesskey="u" rel="up">Expressions</a> [<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="Index-Expressions-1"></a>
<h3 class="section">8.1 Index Expressions</h3>
<a name="index-_0028"></a>
<a name="index-_0029"></a>
<a name="index-_003a-1"></a>
<p>An <em>index expression</em> allows you to reference or extract selected
elements of a matrix or vector.
</p>
<p>Indices may be scalars, vectors, ranges, or the special operator
‘<samp>:</samp>’, which may be used to select entire rows or columns.
</p>
<p>Vectors are indexed using a single index expression. Matrices (2-D)
and higher multi-dimensional arrays are indexed using either one index
or <em>N</em> indices where <em>N</em> is the dimension of the array.
When using a single index expression to index 2-D or higher data the
elements of the array are taken in column-first order (like Fortran).
</p>
<p>The output from indexing assumes the dimensions of the index
expression. For example:
</p>
<div class="example">
<pre class="example">a(2) # result is a scalar
a(1:2) # result is a row vector
a([1; 2]) # result is a column vector
</pre></div>
<p>As a special case, when a colon is used as a single index, the output
is a column vector containing all the elements of the vector or
matrix. For example:
</p>
<div class="example">
<pre class="example">a(:) # result is a column vector
a(:)' # result is a row vector
</pre></div>
<p>The above two code idioms are often used in place of <code>reshape</code>
when a simple vector, rather than an arbitrarily sized array, is
needed.
</p>
<p>Given the matrix
</p>
<div class="example">
<pre class="example">a = [1, 2; 3, 4]
</pre></div>
<p>all of the following expressions are equivalent and select the first
row of the matrix.
</p>
<div class="example">
<pre class="example">a(1, [1, 2]) # row 1, columns 1 and 2
a(1, 1:2) # row 1, columns in range 1-2
a(1, :) # row 1, all columns
</pre></div>
<a name="index-end_002c-indexing"></a>
<a name="index-_003aend"></a>
<p>In index expressions the keyword <code>end</code> automatically refers to
the last entry for a particular dimension. This magic index can also
be used in ranges and typically eliminates the needs to call
<code>size</code> or <code>length</code> to gather array bounds before indexing.
For example:
</p>
<div class="example">
<pre class="example">a = [1, 2, 3, 4];
a(1:end/2) # first half of a => [1, 2]
a(end + 1) = 5; # append element
a(end) = []; # delete element
a(1:2:end) # odd elements of a => [1, 3]
a(2:2:end) # even elements of a => [2, 4]
a(end:-1:1) # reversal of a => [4, 3, 2 , 1]
</pre></div>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top">• <a href="Advanced-Indexing.html#Advanced-Indexing" accesskey="1">Advanced Indexing</a>:</td><td> </td><td align="left" valign="top">
</td></tr>
</table>
<hr>
<div class="header">
<p>
Next: <a href="Calling-Functions.html#Calling-Functions" accesskey="n" rel="next">Calling Functions</a>, Up: <a href="Expressions.html#Expressions" accesskey="u" rel="up">Expressions</a> [<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>
|