Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > 3e60ff9d4d6f58c8fbd17208f14089fa > files > 124

octave-doc-3.2.3-3mdv2010.0.i586.rpm

<html lang="en">
<head>
<title>Creating Cell Arrays - Untitled</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Untitled">
<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="Basic-Usage-of-Cell-Arrays.html#Basic-Usage-of-Cell-Arrays" title="Basic Usage of Cell Arrays">
<link rel="next" href="Indexing-Cell-Arrays.html#Indexing-Cell-Arrays" title="Indexing Cell Arrays">
<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="Creating-Cell-Arrays"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="Indexing-Cell-Arrays.html#Indexing-Cell-Arrays">Indexing Cell Arrays</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="Basic-Usage-of-Cell-Arrays.html#Basic-Usage-of-Cell-Arrays">Basic Usage of Cell Arrays</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Cell-Arrays.html#Cell-Arrays">Cell Arrays</a>
<hr>
</div>

<h4 class="subsection">6.2.2 Creating Cell Array</h4>

<p>The introductory example (see <a href="Basic-Usage-of-Cell-Arrays.html#Basic-Usage-of-Cell-Arrays">Basic Usage of Cell Arrays</a>) showed
how to create a cell array containing currently available variables. 
In many situations, however, it is useful to create a cell array and
then fill it with data.

   <p>The <code>cell</code> function returns a cell array of a given size, containing
empty matrices.  This function is similar to the <code>zeros</code>
function for creating new numerical arrays.  The following example creates
a 2-by-2 cell array containing empty matrices

<pre class="example">     c = cell(2,2)
          &rArr; c =
     
              {
                [1,1] = [](0x0)
                [2,1] = [](0x0)
                [1,2] = [](0x0)
                [2,2] = [](0x0)
              }
</pre>
   <p>Just like numerical arrays, cell arrays can be multidimensional.  The
<code>cell</code> function accepts any number of positive integers to describe
the size of the returned cell array.  It is also possible to set the size
of the cell array through a vector of positive integers.  In the
following example two cell arrays of equal size are created, and the size
of the first one is displayed

<pre class="example">     c1 = cell(3, 4, 5);
     c2 = cell( [3, 4, 5] );
     size(c1)
          &rArr; ans =
              3   4   5
</pre>
   <p class="noindent">As can be seen, the <a href="doc_002dsize.html#doc_002dsize"><code>size</code></a> function also works
for cell arrays.  As do other functions describing the size of an
object, such as <a href="doc_002dlength.html#doc_002dlength"><code>length</code></a>, <a href="doc_002dnumel.html#doc_002dnumel"><code>numel</code></a>, <a href="doc_002drows.html#doc_002drows"><code>rows</code></a>, and <a href="doc_002dcolumns.html#doc_002dcolumns"><code>columns</code></a>.

<!-- ov-cell.cc -->
   <p><a name="doc_002dcell"></a>

<div class="defun">
&mdash; Built-in Function:  <b>cell</b> (<var>x</var>)<var><a name="index-cell-390"></a></var><br>
&mdash; Built-in Function:  <b>cell</b> (<var>n, m</var>)<var><a name="index-cell-391"></a></var><br>
<blockquote><p>Create a new cell array object.  If invoked with a single scalar
argument, <code>cell</code> returns a square cell array with the dimension
specified.  If you supply two scalar arguments, <code>cell</code> takes
them to be the number of rows and columns.  If given a vector with two
elements, <code>cell</code> uses the values of the elements as the number of
rows and columns, respectively. 
</p></blockquote></div>

   <p>As an alternative to creating empty cell arrays, and then filling them, it
is possible to convert numerical arrays into cell arrays using the
<code>num2cell</code> and <code>mat2cell</code> functions.

<!-- ./DLD-FUNCTIONS/cellfun.cc -->
   <p><a name="doc_002dnum2cell"></a>

<div class="defun">
&mdash; Loadable Function: <var>c</var> = <b>num2cell</b> (<var>m</var>)<var><a name="index-num2cell-392"></a></var><br>
&mdash; Loadable Function: <var>c</var> = <b>num2cell</b> (<var>m, dim</var>)<var><a name="index-num2cell-393"></a></var><br>
<blockquote><p>Convert the matrix <var>m</var> to a cell array.  If <var>dim</var> is defined, the
value <var>c</var> is of dimension 1 in this dimension and the elements of
<var>m</var> are placed in slices in <var>c</var>. 
<!-- 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>. 
</p></blockquote></div>

<!-- ./DLD-FUNCTIONS/cellfun.cc -->
   <p><a name="doc_002dmat2cell"></a>

<div class="defun">
&mdash; Loadable Function: <var>b</var> = <b>mat2cell</b> (<var>a, m, n</var>)<var><a name="index-mat2cell-394"></a></var><br>
&mdash; Loadable Function: <var>b</var> = <b>mat2cell</b> (<var>a, d1, d2, <small class="dots">...</small></var>)<var><a name="index-mat2cell-395"></a></var><br>
&mdash; Loadable Function: <var>b</var> = <b>mat2cell</b> (<var>a, r</var>)<var><a name="index-mat2cell-396"></a></var><br>
<blockquote><p>Convert the matrix <var>a</var> to a cell array.  If <var>a</var> is 2-D, then
it is required that <code>sum (</code><var>m</var><code>) == size (</code><var>a</var><code>, 1)</code> and
<code>sum (</code><var>n</var><code>) == size (</code><var>a</var><code>, 2)</code>.  Similarly, if <var>a</var> is
a multi-dimensional and the number of dimensional arguments is equal
to the dimensions of <var>a</var>, then it is required that <code>sum (</code><var>di</var><code>)
== size (</code><var>a</var><code>, i)</code>.

        <p>Given a single dimensional argument <var>r</var>, the other dimensional
arguments are assumed to equal <code>size (</code><var>a</var><code>,</code><var>i</var><code>)</code>.

        <p>An example of the use of mat2cell is

     <pre class="example">          mat2cell (reshape(1:16,4,4),[3,1],[3,1])
          &rArr; {
            [1,1] =
          
               1   5   9
               2   6  10
               3   7  11
          
            [2,1] =
          
               4   8  12
          
            [1,2] =
          
              13
              14
              15
          
            [2,2] = 16
          }
</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_002dnum2cell.html#doc_002dnum2cell">num2cell</a>, <a href="doc_002dcell2mat.html#doc_002dcell2mat">cell2mat</a>. 
</p></blockquote></div>

   </body></html>