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
|
<html lang="en">
<head>
<title>Processing Data in Structures - GNU Octave</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="GNU Octave">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Structures.html#Structures" title="Structures">
<link rel="prev" href="Manipulating-Structures.html#Manipulating-Structures" title="Manipulating Structures">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
pre.display { font-family:inherit }
pre.format { font-family:inherit }
pre.smalldisplay { font-family:inherit; font-size:smaller }
pre.smallformat { font-family:inherit; font-size:smaller }
pre.smallexample { font-size:smaller }
pre.smalllisp { font-size:smaller }
span.sc { font-variant:small-caps }
span.roman { font-family:serif; font-weight:normal; }
span.sansserif { font-family:sans-serif; font-weight:normal; }
--></style>
</head>
<body>
<div class="node">
<a name="Processing-Data-in-Structures"></a>
<p>
Previous: <a rel="previous" accesskey="p" href="Manipulating-Structures.html#Manipulating-Structures">Manipulating Structures</a>,
Up: <a rel="up" accesskey="u" href="Structures.html#Structures">Structures</a>
<hr>
</div>
<h4 class="subsection">6.1.5 Processing Data in Structures</h4>
<p>The simplest way to process data in a structure is within a <code>for</code>
loop (see <a href="Looping-Over-Structure-Elements.html#Looping-Over-Structure-Elements">Looping Over Structure Elements</a>). A similar effect can be
achieved with the <code>structfun</code> function, where a user defined
function is applied to each field of the structure. See <a href="doc_002dstructfun.html#doc_002dstructfun">doc-structfun</a>.
<p>Alternatively, to process the data in a structure, the structure might
be converted to another type of container before being treated.
<!-- struct2cell src/ov-cell.cc -->
<p><a name="doc_002dstruct2cell"></a>
<div class="defun">
— Built-in Function: <b>struct2cell</b> (<var>S</var>)<var><a name="index-struct2cell-453"></a></var><br>
<blockquote><p>Create a new cell array from the objects stored in the struct object.
If <var>f</var> is the number of fields in the structure, the resulting
cell array will have a dimension vector corresponding to
<code>[</code><var>F</var><code> size(</code><var>S</var><code>)]</code>. For example:
<pre class="example"> s = struct('name', {'Peter', 'Hannah', 'Robert'},
'age', {23, 16, 3});
c = struct2cell(s)
⇒ c = {1x1x3 Cell Array}
c(1,1,:)(:)
⇒ ans =
{
[1,1] = Peter
[2,1] = Hannah
[3,1] = Robert
}
c(2,1,:)(:)
⇒ ans =
{
[1,1] = 23
[2,1] = 16
[3,1] = 3
}
</pre>
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->
<p class="noindent"><strong>See also:</strong> <a href="doc_002dcell2struct.html#doc_002dcell2struct">cell2struct</a>, <a href="doc_002dfieldnames.html#doc_002dfieldnames">fieldnames</a>.
</p></blockquote></div>
</body></html>
|