Sophie

Sophie

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

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

<html lang="en">
<head>
<title>Basic Usage of 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="next" href="Creating-Cell-Arrays.html#Creating-Cell-Arrays" title="Creating 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="Basic-Usage-of-Cell-Arrays"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="Creating-Cell-Arrays.html#Creating-Cell-Arrays">Creating 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.1 Basic Usage of Cell Arrays</h4>

<p><a name="index-g_t_0040_007b-455"></a><a name="index-g_t_0040_007d-456"></a>As an example, the following code creates a cell array containing a
string and a 2-by-2 random matrix

<pre class="example">     c = {"a string", rand(2, 2)};
</pre>
   <p class="noindent">To access the elements of a cell array, it can be indexed with the {
and } operators.  Thus, the variable created in the previous example
can be indexed like this:

<pre class="example">     c{1}
          &rArr; ans = a string
</pre>
   <p class="noindent">As with numerical arrays several elements of a cell array can be
extracted by indexing with a vector of indexes

<pre class="example">     c{1:2}
          &rArr; ans = a string
          &rArr; ans =
     
                    0.593993   0.627732
                    0.377037   0.033643
</pre>
   <p>The indexing operators can also be used to insert or overwrite elements
of a cell array.  The following code inserts the scalar 3 on the
third place of the previously created cell array

<pre class="example">     c{3} = 3
          &rArr; c =
     
              {
                [1,1] = a string
                [1,2] =
     
                   0.593993   0.627732
                   0.377037   0.033643
     
                [1,3] =  3
              }
</pre>
   <p>Details on indexing cell arrays are explained in <a href="Indexing-Cell-Arrays.html#Indexing-Cell-Arrays">Indexing Cell Arrays</a>.

   <p>In general nested cell arrays are displayed hierarchically as in the
previous example.  In some circumstances it makes sense to reference
them by their index, and this can be performed by the <code>celldisp</code>
function.

<!-- celldisp scripts/general/celldisp.m -->
   <p><a name="doc_002dcelldisp"></a>

<div class="defun">
&mdash; Function File:  <b>celldisp</b> (<var>c, name</var>)<var><a name="index-celldisp-457"></a></var><br>
<blockquote><p>Recursively display the contents of a cell array.  By default the values
are displayed with the name of the variable <var>c</var>.  However, this name
can be replaced with the variable <var>name</var>.  For example:

     <pre class="example">          c = {1, 2, {31, 32}};
          celldisp (c, "b")
             &rArr;
                b{1} =
                 1
                b{2} =
                 2
                b{3}{1} =
                 31
                b{3}{2} =
                 32
</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_002ddisp.html#doc_002ddisp">disp</a>. 
</p></blockquote></div>

   <p>To test if an object is a cell array, use the <code>iscell</code>
function.  For example:

<pre class="example">     iscell(c)
          &rArr; ans = 1
     
     iscell(3)
          &rArr; ans = 0
</pre>
   <!-- iscell src/ov-cell.cc -->
   <p><a name="doc_002discell"></a>

<div class="defun">
&mdash; Built-in Function:  <b>iscell</b> (<var>x</var>)<var><a name="index-iscell-458"></a></var><br>
<blockquote><p>Return true if <var>x</var> is a cell array object. 
<!-- 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_002dismatrix.html#doc_002dismatrix">ismatrix</a>, <a href="doc_002disstruct.html#doc_002disstruct">isstruct</a>, <a href="doc_002discellstr.html#doc_002discellstr">iscellstr</a>, <a href="doc_002disa.html#doc_002disa">isa</a>. 
</p></blockquote></div>

   </body></html>