/usr/share/doc/octave/octave.html/Manipulating-Structures.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 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 | <!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>Manipulating Structures (GNU Octave)</title>
<meta name="description" content="Manipulating Structures (GNU Octave)">
<meta name="keywords" content="Manipulating Structures (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="Structures.html#Structures" rel="up" title="Structures">
<link href="Processing-Data-in-Structures.html#Processing-Data-in-Structures" rel="next" title="Processing Data in Structures">
<link href="Creating-Structures.html#Creating-Structures" rel="prev" title="Creating Structures">
<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="Manipulating-Structures"></a>
<div class="header">
<p>
Next: <a href="Processing-Data-in-Structures.html#Processing-Data-in-Structures" accesskey="n" rel="next">Processing Data in Structures</a>, Previous: <a href="Creating-Structures.html#Creating-Structures" accesskey="p" rel="prev">Creating Structures</a>, Up: <a href="Structures.html#Structures" accesskey="u" rel="up">Structures</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="Manipulating-Structures-1"></a>
<h4 class="subsection">6.1.4 Manipulating Structures</h4>
<p>Other functions that can manipulate the fields of a structure are given below.
</p>
<a name="XREFnumfields"></a><dl>
<dt><a name="index-numfields"></a>: <em></em> <strong>numfields</strong> <em>(<var>s</var>)</em></dt>
<dd><p>Return the number of fields of the structure <var>s</var>.
</p>
<p><strong>See also:</strong> <a href="#XREFfieldnames">fieldnames</a>.
</p></dd></dl>
<a name="XREFfieldnames"></a><dl>
<dt><a name="index-fieldnames"></a>: <em><var>names</var> =</em> <strong>fieldnames</strong> <em>(<var>struct</var>)</em></dt>
<dt><a name="index-fieldnames-1"></a>: <em><var>names</var> =</em> <strong>fieldnames</strong> <em>(<var>obj</var>)</em></dt>
<dt><a name="index-fieldnames-2"></a>: <em><var>names</var> =</em> <strong>fieldnames</strong> <em>(<var>javaobj</var>)</em></dt>
<dt><a name="index-fieldnames-3"></a>: <em><var>names</var> =</em> <strong>fieldnames</strong> <em>("<var>javaclassname</var>")</em></dt>
<dd><p>Return a cell array of strings with the names of the fields in the
specified input.
</p>
<p>When the input is a structure <var>struct</var>, the names are the elements of
the structure.
</p>
<p>When the input is an Octave object <var>obj</var>, the names are the public
properties of the object.
</p>
<p>When the input is a Java object <var>javaobj</var> or a string containing the
name of a Java class <var>javaclassname</var>, the names are the public fields
(data members) of the object or class.
</p>
<p><strong>See also:</strong> <a href="#XREFnumfields">numfields</a>, <a href="#XREFisfield">isfield</a>, <a href="#XREForderfields">orderfields</a>, <a href="Creating-Structures.html#XREFstruct">struct</a>, <a href="Creating-a-Class.html#XREFmethods">methods</a>.
</p></dd></dl>
<a name="XREFisfield"></a><dl>
<dt><a name="index-isfield"></a>: <em></em> <strong>isfield</strong> <em>(<var>x</var>, "<var>name</var>")</em></dt>
<dt><a name="index-isfield-1"></a>: <em></em> <strong>isfield</strong> <em>(<var>x</var>, <var>name</var>)</em></dt>
<dd><p>Return true if the <var>x</var> is a structure and it includes an element named
<var>name</var>.
</p>
<p>If <var>name</var> is a cell array of strings then a logical array of equal
dimension is returned.
</p>
<p><strong>See also:</strong> <a href="#XREFfieldnames">fieldnames</a>.
</p></dd></dl>
<a name="XREFsetfield"></a><dl>
<dt><a name="index-setfield"></a>: <em><var>sout</var> =</em> <strong>setfield</strong> <em>(<var>s</var>, <var>field</var>, <var>val</var>)</em></dt>
<dt><a name="index-setfield-1"></a>: <em><var>sout</var> =</em> <strong>setfield</strong> <em>(<var>s</var>, <var>sidx1</var>, <var>field1</var>, <var>fidx1</var>, <var>sidx2</var>, <var>field2</var>, <var>fidx2</var>, …, <var>val</var>)</em></dt>
<dd>
<p>Return a <em>copy</em> of the structure <var>s</var> with the field member
<var>field</var> set to the value <var>val</var>.
</p>
<p>For example:
</p>
<div class="example">
<pre class="example"><var>s</var> = struct ();
<var>s</var> = setfield (<var>s</var>, "foo bar", 42);
</pre></div>
<p>This is equivalent to
</p>
<div class="example">
<pre class="example"><var>s</var>.("foo bar") = 42;
</pre></div>
<p>Note that ordinary structure syntax <code><var>s</var>.foo bar = 42</code> cannot be
used here, as the field name is not a valid Octave identifier because of
the space character. Using arbitrary strings for field names is
incompatible with <small>MATLAB</small>, and this usage will emit a warning if the
warning ID <code>Octave:language-extension</code> is enabled.
See <a href="Issuing-Warnings.html#XREFwarning_005fids">warning_ids</a>.
</p>
<p>With the second calling form, set a field of a structure array. The
input <var>sidx</var> selects an element of the structure array, <var>field</var>
specifies the field name of the selected element, and <var>fidx</var> selects
which element of the field (in the case of an array or cell array).
The <var>sidx</var>, <var>field</var>, and <var>fidx</var> inputs can be repeated to
address nested structure array elements. The structure array index and
field element index must be cell arrays while the field name must be a
string.
</p>
<p>For example:
</p>
<div class="example">
<pre class="example"><var>s</var> = struct ("baz", 42);
setfield (<var>s</var>, {1}, "foo", {1}, "bar", 54)
⇒
ans =
scalar structure containing the fields:
baz = 42
foo =
scalar structure containing the fields:
bar = 54
</pre></div>
<p>The example begins with an ordinary scalar structure to which a nested
scalar structure is added. In all cases, if the structure index <var>sidx</var>
is not specified it defaults to 1 (scalar structure). Thus, the example
above could be written more concisely as
<code>setfield (<var>s</var>, "foo", "bar", 54)</code>
</p>
<p>Finally, an example with nested structure arrays:
</p>
<div class="example">
<pre class="example"><var>sa</var>.foo = 1;
<var>sa</var> = setfield (<var>sa</var>, {2}, "bar", {3}, "baz", {1, 4}, 5);
<var>sa</var>(2).bar(3)
⇒
ans =
scalar structure containing the fields:
baz = 0 0 0 5
</pre></div>
<p>Here <var>sa</var> is a structure array whose field at elements 1 and 2 is in
turn another structure array whose third element is a simple scalar
structure. The terminal scalar structure has a field which contains a
matrix value.
</p>
<p>Note that the same result as in the above example could be achieved by:
</p>
<div class="example">
<pre class="example"><var>sa</var>.foo = 1;
<var>sa</var>(2).bar(3).baz(1,4) = 5
</pre></div>
<p><strong>See also:</strong> <a href="#XREFgetfield">getfield</a>, <a href="#XREFrmfield">rmfield</a>, <a href="#XREForderfields">orderfields</a>, <a href="#XREFisfield">isfield</a>, <a href="#XREFfieldnames">fieldnames</a>, <a href="Creating-Structures.html#XREFisstruct">isstruct</a>, <a href="Creating-Structures.html#XREFstruct">struct</a>.
</p></dd></dl>
<a name="XREFgetfield"></a><dl>
<dt><a name="index-getfield"></a>: <em><var>val</var> =</em> <strong>getfield</strong> <em>(<var>s</var>, <var>field</var>)</em></dt>
<dt><a name="index-getfield-1"></a>: <em><var>val</var> =</em> <strong>getfield</strong> <em>(<var>s</var>, <var>sidx1</var>, <var>field1</var>, <var>fidx1</var>, …)</em></dt>
<dd><p>Get the value of the field named <var>field</var> from a structure or nested
structure <var>s</var>.
</p>
<p>If <var>s</var> is a structure array then <var>sidx</var> selects an element of the
structure array, <var>field</var> specifies the field name of the selected
element, and <var>fidx</var> selects which element of the field (in the case of
an array or cell array). See <code>setfield</code> for a more complete
description of the syntax.
</p>
<p><strong>See also:</strong> <a href="#XREFsetfield">setfield</a>, <a href="#XREFrmfield">rmfield</a>, <a href="#XREForderfields">orderfields</a>, <a href="#XREFisfield">isfield</a>, <a href="#XREFfieldnames">fieldnames</a>, <a href="Creating-Structures.html#XREFisstruct">isstruct</a>, <a href="Creating-Structures.html#XREFstruct">struct</a>.
</p></dd></dl>
<a name="XREFrmfield"></a><dl>
<dt><a name="index-rmfield"></a>: <em><var>sout</var> =</em> <strong>rmfield</strong> <em>(<var>s</var>, "<var>f</var>")</em></dt>
<dt><a name="index-rmfield-1"></a>: <em><var>sout</var> =</em> <strong>rmfield</strong> <em>(<var>s</var>, <var>f</var>)</em></dt>
<dd><p>Return a <em>copy</em> of the structure (array) <var>s</var> with the field <var>f</var>
removed.
</p>
<p>If <var>f</var> is a cell array of strings or a character array, remove each of
the named fields.
</p>
<p><strong>See also:</strong> <a href="#XREForderfields">orderfields</a>, <a href="#XREFfieldnames">fieldnames</a>, <a href="#XREFisfield">isfield</a>.
</p></dd></dl>
<a name="XREForderfields"></a><dl>
<dt><a name="index-orderfields"></a>: <em><var>sout</var> =</em> <strong>orderfields</strong> <em>(<var>s1</var>)</em></dt>
<dt><a name="index-orderfields-1"></a>: <em><var>sout</var> =</em> <strong>orderfields</strong> <em>(<var>s1</var>, <var>s2</var>)</em></dt>
<dt><a name="index-orderfields-2"></a>: <em><var>sout</var> =</em> <strong>orderfields</strong> <em>(<var>s1</var>, {<var>cellstr</var>})</em></dt>
<dt><a name="index-orderfields-3"></a>: <em><var>sout</var> =</em> <strong>orderfields</strong> <em>(<var>s1</var>, <var>p</var>)</em></dt>
<dt><a name="index-orderfields-4"></a>: <em>[<var>sout</var>, <var>p</var>] =</em> <strong>orderfields</strong> <em>(…)</em></dt>
<dd><p>Return a <em>copy</em> of <var>s1</var> with fields arranged alphabetically, or as
specified by the second input.
</p>
<p>Given one input struct <var>s1</var>, arrange field names alphabetically.
</p>
<p>If a second struct argument is given, arrange field names in <var>s1</var> as
they appear in <var>s2</var>. The second argument may also specify the order
in a cell array of strings <var>cellstr</var>. The second argument may also
be a permutation vector.
</p>
<p>The optional second output argument <var>p</var> is the permutation vector which
converts the original name order to the new name order.
</p>
<p>Examples:
</p>
<div class="example">
<pre class="example">s = struct ("d", 4, "b", 2, "a", 1, "c", 3);
t1 = orderfields (s)
⇒ t1 =
{
a = 1
b = 2
c = 3
d = 4
}
</pre></div>
<div class="example">
<pre class="example">t = struct ("d", {}, "c", {}, "b", {}, "a", {});
t2 = orderfields (s, t)
⇒ t2 =
{
d = 4
c = 3
b = 2
a = 1
}
</pre></div>
<div class="example">
<pre class="example">t3 = orderfields (s, [3, 2, 4, 1])
⇒ t3 =
{
a = 1
b = 2
c = 3
d = 4
}
</pre></div>
<div class="example">
<pre class="example">[t4, p] = orderfields (s, {"d", "c", "b", "a"})
⇒ t4 =
{
d = 4
c = 3
b = 2
a = 1
}
p =
1
4
2
3
</pre></div>
<p><strong>See also:</strong> <a href="#XREFfieldnames">fieldnames</a>, <a href="#XREFgetfield">getfield</a>, <a href="#XREFsetfield">setfield</a>, <a href="#XREFrmfield">rmfield</a>, <a href="#XREFisfield">isfield</a>, <a href="Creating-Structures.html#XREFisstruct">isstruct</a>, <a href="Creating-Structures.html#XREFstruct">struct</a>.
</p></dd></dl>
<a name="XREFsubstruct"></a><dl>
<dt><a name="index-substruct"></a>: <em></em> <strong>substruct</strong> <em>(<var>type</var>, <var>subs</var>, …)</em></dt>
<dd><p>Create a subscript structure for use with <code>subsref</code> or <code>subsasgn</code>.
</p>
<p>For example:
</p>
<div class="example">
<pre class="example">idx = substruct ("()", {3, ":"})
⇒
idx =
{
type = ()
subs =
{
[1,1] = 3
[1,2] = :
}
}
x = [1, 2, 3;
4, 5, 6;
7, 8, 9];
subsref (x, idx)
⇒ 7 8 9
</pre></div>
<p><strong>See also:</strong> <a href="Defining-Indexing-And-Indexed-Assignment.html#XREFsubsref">subsref</a>, <a href="Defining-Indexing-And-Indexed-Assignment.html#XREFsubsasgn">subsasgn</a>.
</p></dd></dl>
<hr>
<div class="header">
<p>
Next: <a href="Processing-Data-in-Structures.html#Processing-Data-in-Structures" accesskey="n" rel="next">Processing Data in Structures</a>, Previous: <a href="Creating-Structures.html#Creating-Structures" accesskey="p" rel="prev">Creating Structures</a>, Up: <a href="Structures.html#Structures" accesskey="u" rel="up">Structures</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>
|