/usr/share/doc/octave/octave.html/Indexing-Cell-Arrays.html is in octave-doc 4.2.2-1ubuntu1.
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 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | <!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>Indexing Cell Arrays (GNU Octave)</title>
<meta name="description" content="Indexing Cell Arrays (GNU Octave)">
<meta name="keywords" content="Indexing Cell Arrays (GNU Octave)">
<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="Cell-Arrays.html#Cell-Arrays" rel="up" title="Cell Arrays">
<link href="Cell-Arrays-of-Strings.html#Cell-Arrays-of-Strings" rel="next" title="Cell Arrays of Strings">
<link href="Creating-Cell-Arrays.html#Creating-Cell-Arrays" rel="prev" title="Creating Cell Arrays">
<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="Indexing-Cell-Arrays"></a>
<div class="header">
<p>
Next: <a href="Cell-Arrays-of-Strings.html#Cell-Arrays-of-Strings" accesskey="n" rel="next">Cell Arrays of Strings</a>, Previous: <a href="Creating-Cell-Arrays.html#Creating-Cell-Arrays" accesskey="p" rel="prev">Creating Cell Arrays</a>, Up: <a href="Cell-Arrays.html#Cell-Arrays" accesskey="u" rel="up">Cell Arrays</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="Indexing-Cell-Arrays-1"></a>
<h4 class="subsection">6.2.3 Indexing Cell Arrays</h4>
<p>As shown in see <a href="Basic-Usage-of-Cell-Arrays.html#Basic-Usage-of-Cell-Arrays">Basic Usage of Cell Arrays</a> elements can be
extracted from cell arrays using the ‘<samp>{</samp>’ and ‘<samp>}</samp>’
operators. If you want to extract or access subarrays which are still
cell arrays, you need to use the ‘<samp>(</samp>’ and ‘<samp>)</samp>’ operators. The
following example illustrates the difference:
</p>
<div class="example">
<pre class="example">c = {"1", "2", "3"; "x", "y", "z"; "4", "5", "6"};
c{2,3}
⇒ ans = z
c(2,3)
⇒ ans =
{
[1,1] = z
}
</pre></div>
<p>So with ‘<samp>{}</samp>’ you access elements of a cell
array, while with ‘<samp>()</samp>’ you access a sub array of a cell
array.
</p>
<p>Using the ‘<samp>(</samp>’ and ‘<samp>)</samp>’ operators, indexing works for cell
arrays like for multi-dimensional arrays. As an example, all the rows
of the first and third column of a cell array can be set to <code>0</code>
with the following command:
</p>
<div class="example">
<pre class="example">c(:, [1, 3]) = {0}
⇒ =
{
[1,1] = 0
[2,1] = 0
[3,1] = 0
[1,2] = 2
[2,2] = y
[3,2] = 5
[1,3] = 0
[2,3] = 0
[3,3] = 0
}
</pre></div>
<p>Note, that the above can also be achieved like this:
</p>
<div class="example">
<pre class="example">c(:, [1, 3]) = 0;
</pre></div>
<p>Here, the scalar ‘<samp>0</samp>’ is automatically promoted to
cell array ‘<samp>{0}</samp>’ and then assigned to the subarray of <code>c</code>.
</p>
<p>To give another example for indexing cell arrays with ‘<samp>()</samp>’, you
can exchange the first and the second row of a cell array as in the
following command:
</p>
<div class="example">
<pre class="example">c = {1, 2, 3; 4, 5, 6};
c([1, 2], :) = c([2, 1], :)
⇒ =
{
[1,1] = 4
[2,1] = 1
[1,2] = 5
[2,2] = 2
[1,3] = 6
[2,3] = 3
}
</pre></div>
<p>Accessing multiple elements of a cell array with the ‘<samp>{</samp>’ and
‘<samp>}</samp>’ operators will result in a comma-separated list of all the
requested elements (see <a href="Comma-Separated-Lists.html#Comma-Separated-Lists">Comma Separated Lists</a>). Using the
‘<samp>{</samp>’ and ‘<samp>}</samp>’ operators the first two rows in the above
example can be swapped back like this:
</p>
<div class="example">
<pre class="example">[c{[1,2], :}] = deal (c{[2, 1], :})
⇒ =
{
[1,1] = 1
[2,1] = 4
[1,2] = 2
[2,2] = 5
[1,3] = 3
[2,3] = 6
}
</pre></div>
<p>As for struct arrays and numerical arrays, the empty matrix ‘<samp>[]</samp>’
can be used to delete elements from a cell array:
</p>
<div class="example">
<pre class="example">x = {"1", "2"; "3", "4"};
x(1, :) = []
⇒ x =
{
[1,1] = 3
[1,2] = 4
}
</pre></div>
<p>The following example shows how to just remove the contents of cell
array elements but not delete the space for them:
</p>
<div class="example">
<pre class="example">x = {"1", "2"; "3", "4"};
x(1, :) = {[]}
⇒ x =
{
[1,1] = [](0x0)
[2,1] = 3
[1,2] = [](0x0)
[2,2] = 4
}
</pre></div>
<p>The indexing operations operate on the cell array and not on the objects
within the cell array. By contrast, <code>cellindexmat</code> applies matrix
indexing to the objects within each cell array entry and returns the requested
values.
</p>
<a name="XREFcellindexmat"></a><dl>
<dt><a name="index-cellindexmat"></a>: <em><var>y</var> =</em> <strong>cellindexmat</strong> <em>(<var>x</var>, <var>varargin</var>)</em></dt>
<dd><p>Perform indexing of matrices in a cell array.
</p>
<p>Given a cell array of matrices <var>x</var>, this function computes
</p>
<div class="example">
<pre class="example">Y = cell (size (X));
for i = 1:numel (X)
Y{i} = X{i}(varargin{1}, varargin{2}, …, varargin{N});
endfor
</pre></div>
<p>The indexing arguments may be scalar (<code>2</code>), arrays (<code>[1, 3]</code>),
ranges (<code>1:3</code>), or the colon operator (<code>":"</code>). However, the
indexing keyword <code>end</code> is not available.
</p>
<p><strong>See also:</strong> <a href="Creating-Cell-Arrays.html#XREFcellslices">cellslices</a>, <a href="Function-Application.html#XREFcellfun">cellfun</a>.
</p></dd></dl>
<hr>
<div class="header">
<p>
Next: <a href="Cell-Arrays-of-Strings.html#Cell-Arrays-of-Strings" accesskey="n" rel="next">Cell Arrays of Strings</a>, Previous: <a href="Creating-Cell-Arrays.html#Creating-Cell-Arrays" accesskey="p" rel="prev">Creating Cell Arrays</a>, Up: <a href="Cell-Arrays.html#Cell-Arrays" accesskey="u" rel="up">Cell Arrays</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>
|