/usr/share/doc/octave-htmldoc/interpreter/Manipulating-Structures.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 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 | <!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: Manipulating Structures</title>
<meta name="description" content="GNU Octave: Manipulating Structures">
<meta name="keywords" content="GNU Octave: Manipulating Structures">
<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="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.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="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="XREFnfields"></a><dl>
<dt><a name="index-nfields"></a>Built-in Function: <em></em> <strong>nfields</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>Function File: <em><var>names</var> =</em> <strong>fieldnames</strong> <em>(<var>struct</var>)</em></dt>
<dt><a name="index-fieldnames-1"></a>Function File: <em><var>names</var> =</em> <strong>fieldnames</strong> <em>(<var>obj</var>)</em></dt>
<dt><a name="index-fieldnames-2"></a>Function File: <em><var>names</var> =</em> <strong>fieldnames</strong> <em>(<var>javaobj</var>)</em></dt>
<dt><a name="index-fieldnames-3"></a>Function File: <em><var>names</var> =</em> <strong>fieldnames</strong> <em>("<var>jclassname</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 Java classname
<var>jclassname</var> the name are the public data elements of the object or
class.
</p>
<p><strong>See also:</strong> <a href="#XREFnfields">nfields</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>Built-in Function: <em></em> <strong>isfield</strong> <em>(<var>x</var>, "<var>name</var>")</em></dt>
<dt><a name="index-isfield-1"></a>Built-in Function: <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>. 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>Function File: <em><var>s</var> =</em> <strong>setfield</strong> <em>(<var>s</var>, <var>field</var>, <var>val</var>)</em></dt>
<dt><a name="index-setfield-1"></a>Function File: <em><var>s</var> =</em> <strong>setfield</strong> <em>(<var>s</var>, <var>idx1</var>, <var>field1</var>, <var>idx2</var>, <var>field2</var>, …, <var>val</var>)</em></dt>
<dd>
<p>Set a field member <var>field</var> in a structure <var>s</var> equal to <var>val</var>.
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. Using
arbitrary strings for field name is incompatible with <small>MATLAB</small>, so
this usage will warn if the <code>Octave:matlab-incompatible</code> warning
is set. See <a href="Issuing-Warnings.html#XREFwarning_005fids">XREFwarning_ids</a>.
</p>
<p>With the second calling form, set a field on a structure array,
possibly nested, with successive nested indices <var>idx1</var>,
<var>idx2</var>, … and fields <var>field1</var>, <var>field2</var>, …
The indices must be cells containing the desired index at this
nesting depth.
</p>
<p>Thus consider instead,
</p>
<div class="example">
<pre class="example"><var>s</var> = struct ("baz", 42);
setfield (<var>s</var>, {1}, "foo", {1}, "bar", 5)
⇒ ans =
scalar structure containing the fields:
baz = 42
foo =
scalar structure containing the fields:
bar = 54
</pre></div>
<p>Here we first have an ordinary structure array with one field
<code>baz</code> set to 42. Then we set another field in a nested scalar structure
indexing with two single cells containing the unique desired indices.
</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", 6);
<var>sa</var>(2).bar(3)
⇒ ans =
scalar structure containing the fields:
baz = 6
</pre></div>
<p>Here <var>sa</var> is a structure array whose field <code>fd</code> at elements
1 and 2 field is in turn
another structure array whose third element is a structure
</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 = 6
</pre></div>
<p><strong>See also:</strong> <a href="#XREFgetfield">getfield</a>, <a href="#XREFrmfield">rmfield</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>Function File: <em>[<var>val</var>] =</em> <strong>getfield</strong> <em>(<var>s</var>, <var>field</var>)</em></dt>
<dt><a name="index-getfield-1"></a>Function File: <em>[<var>val</var>] =</em> <strong>getfield</strong> <em>(<var>s</var>, <var>idx1</var>, <var>field1</var>, <var>idx2</var>, <var>field2</var>, …)</em></dt>
<dd><p>Extract a field from a structure (or a nested structure). The syntax
is the same as <code>setfield</code>, except it omits the final <var>val</var>
argument, returning this value instead of setting it.
</p>
<p><strong>See also:</strong> <a href="#XREFsetfield">setfield</a>, <a href="#XREFrmfield">rmfield</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>Built-in Function: <em><var>s</var> =</em> <strong>rmfield</strong> <em>(<var>s</var>, "<var>f</var>")</em></dt>
<dt><a name="index-rmfield-1"></a>Built-in Function: <em><var>s</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. 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>.
</p></dd></dl>
<a name="XREForderfields"></a><dl>
<dt><a name="index-orderfields"></a>Function File: <em>[<var>t</var>, <var>p</var>] =</em> <strong>orderfields</strong> <em>(<var>s1</var>)</em></dt>
<dt><a name="index-orderfields-1"></a>Function File: <em>[<var>t</var>, <var>p</var>] =</em> <strong>orderfields</strong> <em>(<var>s1</var>, <var>s2</var>)</em></dt>
<dd><p>Return a copy of <var>s1</var> with fields arranged alphabetically or as
specified by <var>s2</var>.
</p>
<p>Given one struct, arrange field names in <var>s1</var> alphabetically.
</p>
<p>If the second argument is a struct, arrange field names in <var>s1</var> as they
appear in <var>s2</var>. The second argument may also specify the order in a
permutation vector or a cell array of strings containing the fieldnames of
<var>s1</var> in the desired order.
</p>
<p>The optional second output argument <var>p</var> is assigned the permutation
vector which converts the original name order into 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><pre class="example">t = struct ("d", {}, "c", {}, "b", {}, "a", {});
t2 = orderfields (s, t)
⇒ t2 =
{
d = 4
c = 3
b = 2
a = 1
}
</pre><pre class="example">t3 = orderfields (s, [3, 2, 4, 1])
⇒ t3 =
{
a = 1
b = 2
c = 3
d = 4
}
</pre><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="#XREFgetfield">getfield</a>, <a href="#XREFrmfield">rmfield</a>, <a href="#XREFisfield">isfield</a>, <a href="Creating-Structures.html#XREFisstruct">isstruct</a>, <a href="#XREFfieldnames">fieldnames</a>, <a href="Creating-Structures.html#XREFstruct">struct</a>.
</p></dd></dl>
<a name="XREFsubstruct"></a><dl>
<dt><a name="index-substruct"></a>Function File: <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>. 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>
|