Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > b38d2da330d1936e5ab1307c039c4941 > files > 418

octave-doc-3.6.4-3.mga4.noarch.rpm

<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:&nbsp;<a rel="previous" accesskey="p" href="Manipulating-Structures.html#Manipulating-Structures">Manipulating Structures</a>,
Up:&nbsp;<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">
&mdash; 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)
               &rArr; c = {1x1x3 Cell Array}
            c(1,1,:)(:)
               &rArr; ans =
                  {
                    [1,1] = Peter
                    [2,1] = Hannah
                    [3,1] = Robert
                  }
            c(2,1,:)(:)
               &rArr; 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>