File: Basic-Usage-of-Cell-Arrays.html

package info (click to toggle)
octave3.2 3.2.4-8
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 62,936 kB
  • ctags: 37,353
  • sloc: cpp: 219,497; fortran: 116,336; ansic: 10,264; sh: 5,508; makefile: 4,245; lex: 3,573; yacc: 3,062; objc: 2,042; lisp: 1,692; awk: 860; perl: 844
file content (120 lines) | stat: -rw-r--r-- 4,307 bytes parent folder | download
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<html lang="en">
<head>
<title>Basic Usage of Cell Arrays - Untitled</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Untitled">
<meta name="generator" content="makeinfo 4.11">
<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">
<p>
<a name="Basic-Usage-of-Cell-Arrays"></a>
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>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}
           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}
           ans =
     
               (,
                 [1] = a string
                 [2] =
     
                    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
           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.

<!-- ./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-388"></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>. 
<!-- 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)
           ans = 1
     
     iscell(3)
           ans = 0
</pre>
   <!-- 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-389"></a></var><br>
<blockquote><p>Return true if <var>x</var> is a cell array object.  Otherwise, return
false. 
</p></blockquote></div>

   </body></html>