<html lang="en"> <head> <title>Processing Data in Cell Arrays - 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="Cell-Arrays.html#Cell-Arrays" title="Cell Arrays"> <link rel="prev" href="Cell-Arrays-of-Strings.html#Cell-Arrays-of-Strings" title="Cell Arrays of Strings"> <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-Cell-Arrays"></a> <p> Previous: <a rel="previous" accesskey="p" href="Cell-Arrays-of-Strings.html#Cell-Arrays-of-Strings">Cell Arrays of Strings</a>, Up: <a rel="up" accesskey="u" href="Cell-Arrays.html#Cell-Arrays">Cell Arrays</a> <hr> </div> <h4 class="subsection">6.2.5 Processing Data in Cell Arrays</h4> <p>Data that is stored in a cell array can be processed in several ways depending on the actual data. The simplest way to process that data is to iterate through it using one or more <code>for</code> loops. The same idea can be implemented more easily through the use of the <code>cellfun</code> function that calls a user-specified function on all elements of a cell array. See <a href="doc_002dcellfun.html#doc_002dcellfun">doc-cellfun</a>. <p>An alternative is to convert the data to a different container, such as a matrix or a data structure. Depending on the data this is possible using the <code>cell2mat</code> and <code>cell2struct</code> functions. <!-- cell2mat scripts/general/cell2mat.m --> <p><a name="doc_002dcell2mat"></a> <div class="defun"> — Function File: <var>m</var> = <b>cell2mat</b> (<var>c</var>)<var><a name="index-cell2mat-472"></a></var><br> <blockquote><p>Convert the cell array <var>c</var> into a matrix by concatenating all elements of <var>c</var> into a hyperrectangle. Elements of <var>c</var> must be numeric, logical or char matrices, or cell arrays, and <code>cat</code> must be able to concatenate them together. <!-- 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_002dmat2cell.html#doc_002dmat2cell">mat2cell</a>, <a href="doc_002dnum2cell.html#doc_002dnum2cell">num2cell</a>. </p></blockquote></div> <!-- cell2struct src/ov-struct.cc --> <p><a name="doc_002dcell2struct"></a> <div class="defun"> — Built-in Function: <b>cell2struct</b> (<var>cell, fields, dim</var>)<var><a name="index-cell2struct-473"></a></var><br> <blockquote><p>Convert <var>cell</var> to a structure. The number of fields in <var>fields</var> must match the number of elements in <var>cell</var> along dimension <var>dim</var>, that is <code>numel (</code><var>fields</var><code>) == size (</code><var>cell</var><code>, </code><var>dim</var><code>)</code>. If <var>dim</var> is omitted, a value of 1 is assumed. <pre class="example"> A = cell2struct ({'Peter', 'Hannah', 'Robert'; 185, 170, 168}, {'Name','Height'}, 1); A(1) ⇒ ans = { Name = Peter Height = 185 } </pre> </blockquote></div> </body></html>