annotate doc/interpreter/container.txi @ 12175:2090995ca588

Correct en-dash,em-dash instances in docstrings. Add a few more operators to operator index.
author Rik <octave@nomad.inbox5.com>
date Wed, 26 Jan 2011 20:51:20 -0800
parents a4b0e292107f
children 1eb430d9a1b9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11523
fd0a3ac60b0e update copyright notices
John W. Eaton <jwe@octave.org>
parents: 11474
diff changeset
1 @c Copyright (C) 1996-2011 John W. Eaton
7018
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
2 @c
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
3 @c This file is part of Octave.
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
4 @c
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
5 @c Octave is free software; you can redistribute it and/or modify it
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
6 @c under the terms of the GNU General Public License as published by the
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
7 @c Free Software Foundation; either version 3 of the License, or (at
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
8 @c your option) any later version.
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
9 @c
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
10 @c Octave is distributed in the hope that it will be useful, but WITHOUT
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
11 @c ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
12 @c FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
13 @c for more details.
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
14 @c
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
15 @c You should have received a copy of the GNU General Public License
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
16 @c along with Octave; see the file COPYING. If not, see
fd42779a8428 [project @ 2007-10-13 00:52:12 by jwe]
jwe
parents: 7001
diff changeset
17 @c <http://www.gnu.org/licenses/>.
3439
3234a698073a [project @ 2000-01-14 09:51:14 by jwe]
jwe
parents:
diff changeset
18
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
19 @node Data Containers
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
20 @chapter Data Containers
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
21 @cindex containers
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
22
6939
46d1ad37d943 [project @ 2007-10-01 16:12:20 by jwe]
jwe
parents: 6868
diff changeset
23 Octave includes support for two different mechanisms to contain
9036
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
24 arbitrary data types in the same variable. Structures, which are C-like,
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
25 and are indexed with named fields, and cell arrays, where each element
9758
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9312
diff changeset
26 of the array can have a different data type and or shape. Multiple
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
27 input arguments and return values of functions are organized as
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
28 another data container, the comma separated list.
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
29
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
30 @menu
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
31 * Data Structures::
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
32 * Cell Arrays::
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
33 * Comma Separated Lists::
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
34 @end menu
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
35
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
36 @node Data Structures
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
37 @section Data Structures
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
38 @cindex structures
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
39 @cindex data structures
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
40
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
41 Octave includes support for organizing data in structures. The current
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
42 implementation uses an associative array with indices limited to
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
43 strings, but the syntax is more like C-style structures.
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
44
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
45 @menu
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
46 * Basic Usage and Examples::
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
47 * Structure Arrays::
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
48 * Creating Structures::
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
49 * Manipulating Structures::
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
50 * Processing Data in Structures::
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
51 @end menu
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
52
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
53 @node Basic Usage and Examples
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
54 @subsection Basic Usage and Examples
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
55
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
56 Here are some examples of using data structures in Octave.
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
57
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
58 Elements of structures can be of any value type. For example, the three
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
59 expressions
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
60
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
61 @example
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
62 @group
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
63 x.a = 1;
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
64 x.b = [1, 2; 3, 4];
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
65 x.c = "string";
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
66 @end group
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
67 @end example
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
68
12175
2090995ca588 Correct en-dash,em-dash instances in docstrings.
Rik <octave@nomad.inbox5.com>
parents: 11537
diff changeset
69 @opindex .
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
70 @noindent
12175
2090995ca588 Correct en-dash,em-dash instances in docstrings.
Rik <octave@nomad.inbox5.com>
parents: 11537
diff changeset
71 create a structure with three elements. The @samp{.} character separates
2090995ca588 Correct en-dash,em-dash instances in docstrings.
Rik <octave@nomad.inbox5.com>
parents: 11537
diff changeset
72 the structure name from the field name and indicates to Octave that this
2090995ca588 Correct en-dash,em-dash instances in docstrings.
Rik <octave@nomad.inbox5.com>
parents: 11537
diff changeset
73 variable is a structure. To print the value of the
2090995ca588 Correct en-dash,em-dash instances in docstrings.
Rik <octave@nomad.inbox5.com>
parents: 11537
diff changeset
74 structure you can type its name, just as for any other variable:
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
75
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
76 @example
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
77 @group
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
78 x
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
79 @result{} x =
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
80 @{
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
81 a = 1
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
82 b =
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
83
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
84 1 2
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
85 3 4
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
86
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
87 c = string
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
88 @}
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
89 @end group
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
90 @end example
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
91
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
92 @noindent
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
93 Note that Octave may print the elements in any order.
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
94
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
95 Structures may be copied just like any other variable:
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
96
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
97 @example
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
98 @group
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
99 y = x
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
100 @result{} y =
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
101 @{
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
102 a = 1
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
103 b =
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
104
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
105 1 2
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
106 3 4
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
107
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
108 c = string
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
109 @}
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
110 @end group
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
111 @end example
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
112
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
113 Since structures are themselves values, structure elements may reference
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
114 other structures. The following statements change the value of the
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
115 element @code{b} of the structure @code{x} to be a data structure
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
116 containing the single element @code{d}, which has a value of 3.
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
117
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
118 @example
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
119 @group
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
120 x.b.d = 3;
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
121 x.b
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
122 @result{} ans =
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
123 @{
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
124 d = 3
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
125 @}
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
126
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
127 x
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
128 @result{} x =
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
129 @{
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
130 a = 1
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
131 b =
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
132 @{
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
133 d = 3
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
134 @}
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
135
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
136 c = string
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
137 @}
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
138 @end group
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
139 @end example
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
140
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
141 Note that when Octave prints the value of a structure that contains
10828
322f43e0e170 Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents: 10122
diff changeset
142 other structures, only a few levels are displayed. For example:
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
143
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
144 @example
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
145 @group
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
146 a.b.c.d.e = 1;
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
147 a
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
148 @result{} a =
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
149 @{
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
150 b =
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
151 @{
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
152 c =
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
153 @{
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
154 1x1 struct array containing the fields:
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
155
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
156 d: 1x1 struct
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
157 @}
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
158 @}
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
159 @}
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
160 @end group
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
161 @end example
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
162
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
163 @noindent
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
164 This prevents long and confusing output from large deeply nested
11474
8a40037533e2 struct printing changes
John W. Eaton <jwe@octave.org>
parents: 11392
diff changeset
165 structures. The number of levels to print for nested structures may be
8a40037533e2 struct printing changes
John W. Eaton <jwe@octave.org>
parents: 11392
diff changeset
166 set with the function @code{struct_levels_to_print}, and the function
8a40037533e2 struct printing changes
John W. Eaton <jwe@octave.org>
parents: 11392
diff changeset
167 @code{print_struct_array_contents} may be used to enable printing of the
8a40037533e2 struct printing changes
John W. Eaton <jwe@octave.org>
parents: 11392
diff changeset
168 contents of structure arrays.
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
169
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
170 @DOCSTRING(struct_levels_to_print)
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
171
11474
8a40037533e2 struct printing changes
John W. Eaton <jwe@octave.org>
parents: 11392
diff changeset
172 @DOCSTRING(print_struct_array_contents)
8a40037533e2 struct printing changes
John W. Eaton <jwe@octave.org>
parents: 11392
diff changeset
173
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
174 Functions can return structures. For example, the following function
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
175 separates the real and complex parts of a matrix and stores them in two
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
176 elements of the same structure variable.
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
177
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
178 @example
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
179 @group
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
180 function y = f (x)
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
181 y.re = real (x);
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
182 y.im = imag (x);
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
183 endfunction
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
184 @end group
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
185 @end example
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
186
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
187 When called with a complex-valued argument, @code{f} returns the data
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
188 structure containing the real and imaginary parts of the original
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
189 function argument.
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
190
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
191 @example
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
192 @group
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
193 f (rand (2) + rand (2) * I)
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
194 @result{} ans =
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
195 @{
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
196 im =
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
197
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
198 0.26475 0.14828
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
199 0.18436 0.83669
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
200
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
201 re =
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
202
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
203 0.040239 0.242160
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
204 0.238081 0.402523
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
205
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
206 @}
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
207 @end group
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
208 @end example
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
209
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
210 Function return lists can include structure elements, and they may be
10828
322f43e0e170 Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents: 10122
diff changeset
211 indexed like any other variable. For example:
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
212
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
213 @example
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
214 [ x.u, x.s(2:3,2:3), x.v ] = svd ([1, 2; 3, 4]);
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
215 x
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
216 @result{} x =
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
217 @{
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
218 u =
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
219
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
220 -0.40455 -0.91451
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
221 -0.91451 0.40455
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
222
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
223 s =
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
224
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
225 0.00000 0.00000 0.00000
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
226 0.00000 5.46499 0.00000
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
227 0.00000 0.00000 0.36597
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
228
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
229 v =
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
230
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
231 -0.57605 0.81742
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
232 -0.81742 -0.57605
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
233
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
234 @}
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
235 @end example
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
236
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
237 It is also possible to cycle through all the elements of a structure in
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
238 a loop, using a special form of the @code{for} statement
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
239 (@pxref{Looping Over Structure Elements}).
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
240
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
241 @node Structure Arrays
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
242 @subsection Structure Arrays
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
243
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
244 A structure array is a particular instance of a structure, where each of
9036
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
245 the fields of the structure is represented by a cell array. Each of
9758
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9312
diff changeset
246 these cell arrays has the same dimensions. Conceptually, a structure
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
247 array can also be seen as an array of structures with identical
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
248 fields. An example of the creation of a structure array is
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
249
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
250 @example
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
251 @group
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
252 x(1).a = "string1";
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
253 x(2).a = "string2";
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
254 x(1).b = 1;
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
255 x(2).b = 2;
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
256 @end group
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
257 @end example
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
258
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
259 @noindent
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
260 which creates a 2-by-1 structure array with two fields. Another way
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
261 to create a structure array is with the @code{struct} function
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
262 (@pxref{Creating Structures}). As previously, to print the value of
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
263 the structure array, you can type its name:
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
264
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
265 @example
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
266 @group
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
267 x
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
268 @result{} x =
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
269 @{
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
270 1x2 struct array containing the fields:
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
271
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
272 a
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
273 b
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
274 @}
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
275 @end group
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
276 @end example
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
277
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
278 Individual elements of the structure array can be returned by indexing
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
279 the variable like @code{@var{x}(1)}, which returns a structure with
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
280 two fields:
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
281
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
282 @example
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
283 @group
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
284 x(1)
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
285 @result{} ans =
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
286 @{
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
287 a = string1
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
288 b = 1
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
289 @}
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
290 @end group
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
291 @end example
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
292
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
293 Furthermore, the structure array can return a comma separated list of
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
294 field values (@pxref{Comma Separated Lists}), if indexed by one of its
10828
322f43e0e170 Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents: 10122
diff changeset
295 own field names. For example:
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
296
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
297 @example
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
298 @group
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
299 x.a
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
300 @result{}
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
301 ans = string1
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
302 ans = string2
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
303 @end group
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
304 @end example
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
305
8584
848f7d3e589c Update the examples for structure arrays in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8541
diff changeset
306 Here is another example, using this comma separated list on the
848f7d3e589c Update the examples for structure arrays in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8541
diff changeset
307 left-hand side of an assignment:
848f7d3e589c Update the examples for structure arrays in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8541
diff changeset
308
848f7d3e589c Update the examples for structure arrays in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8541
diff changeset
309 @example
848f7d3e589c Update the examples for structure arrays in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8541
diff changeset
310 @group
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
311 [x.a] = deal("new string1", "new string2");
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
312 x(1).a
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
313 @result{} ans = new string1
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
314 x(2).a
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
315 @result{} ans = new string2
8584
848f7d3e589c Update the examples for structure arrays in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8541
diff changeset
316 @end group
848f7d3e589c Update the examples for structure arrays in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8541
diff changeset
317 @end example
848f7d3e589c Update the examples for structure arrays in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8541
diff changeset
318
10828
322f43e0e170 Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents: 10122
diff changeset
319 Just as for numerical arrays, it is possible to use vectors as indices
322f43e0e170 Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents: 10122
diff changeset
320 (@pxref{Index Expressions}):
8584
848f7d3e589c Update the examples for structure arrays in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8541
diff changeset
321
848f7d3e589c Update the examples for structure arrays in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8541
diff changeset
322 @example
848f7d3e589c Update the examples for structure arrays in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8541
diff changeset
323 @group
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
324 x(3:4) = x(1:2);
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
325 [x([1,3]).a] = deal("other string1", "other string2");
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
326 x.a
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
327 @result{}
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
328 ans = other string1
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
329 ans = new string2
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
330 ans = other string2
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
331 ans = new string2
8584
848f7d3e589c Update the examples for structure arrays in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8541
diff changeset
332 @end group
848f7d3e589c Update the examples for structure arrays in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8541
diff changeset
333 @end example
848f7d3e589c Update the examples for structure arrays in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 8541
diff changeset
334
9036
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
335 The function @code{size} will return the size of the structure. For
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
336 the example above
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
337
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
338 @example
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
339 @group
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
340 size(x)
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
341 @result{} ans =
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
342
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
343 1 4
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
344 @end group
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
345 @end example
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
346
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
347 Elements can be deleted from a structure array in a similar manner to a
9036
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
348 numerical array, by assigning the elements to an empty matrix. For
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
349 example
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
350
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
351 @example
9758
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9312
diff changeset
352 @group
7031
120f3135952f [project @ 2007-10-15 15:30:03 by jwe]
jwe
parents: 7025
diff changeset
353 in = struct ("call1", @{x, Inf, "last"@},
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
354 "call2", @{x, Inf, "first"@})
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
355 @result{} in =
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
356 @{
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
357 1x3 struct array containing the fields:
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
358
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
359 call1
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
360 call2
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
361 @}
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
362
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
363 in(1) = [];
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
364 in.call1
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
365 @result{}
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
366 ans = Inf
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
367 ans = last
9758
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9312
diff changeset
368 @end group
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
369 @end example
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
370
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
371 @node Creating Structures
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
372 @subsection Creating Structures
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
373
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
374 As well as indexing a structure with ".", Octave can create a structure
9036
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
375 with the @code{struct} command. @code{struct} takes pairs of arguments,
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
376 where the first argument in the pair is the fieldname to include in the
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
377 structure and the second is a scalar or cell array, representing the
10828
322f43e0e170 Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents: 10122
diff changeset
378 values to include in the structure or structure array. For example:
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
379
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
380 @example
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
381 @group
7031
120f3135952f [project @ 2007-10-15 15:30:03 by jwe]
jwe
parents: 7025
diff changeset
382 struct ("field1", 1, "field2", 2)
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
383 @result{} ans =
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
384 @{
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
385 field1 = 1
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
386 field2 = 2
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
387 @}
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
388 @end group
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
389 @end example
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
390
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
391 If the values passed to @code{struct} are a mix of scalar and cell
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
392 arrays, then the scalar arguments are expanded to create a
10828
322f43e0e170 Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents: 10122
diff changeset
393 structure array with a consistent dimension. For example:
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
394
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
395 @example
9758
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9312
diff changeset
396 @group
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
397 s = struct ("field1", @{1, "one"@}, "field2", @{2, "two"@},
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
398 "field3", 3);
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
399 s.field1
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
400 @result{}
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
401 ans = 1
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
402 ans = one
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
403
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
404 s.field2
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
405 @result{}
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
406 ans = 2
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
407 ans = two
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
408
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
409 s.field3
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
410 @result{}
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
411 ans = 3
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
412 ans = 3
9758
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9312
diff changeset
413 @end group
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
414 @end example
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
415
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
416 If you want to create a struct which contains a cell array as an
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
417 individual field, you have to put it into another cell array like in
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
418 the following example:
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
419
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
420 @example
9758
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9312
diff changeset
421 @group
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
422 struct ("field1", @{@{1, "one"@}@}, "field2", 2)
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
423 @result{} ans =
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
424 @{
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
425 field1 =
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
426
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
427 @{
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
428 [1,1] = 1
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
429 [1,2] = one
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
430 @}
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
431
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
432 field2 = 2
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
433 @}
9758
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9312
diff changeset
434 @end group
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
435 @end example
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
436
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
437 @DOCSTRING(struct)
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
438
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
439 The function @code{isstruct} can be used to test if an object is a
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
440 structure or a structure array.
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
441
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
442 @DOCSTRING(isstruct)
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
443
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
444 @node Manipulating Structures
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
445 @subsection Manipulating Structures
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
446
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
447 Other functions that can manipulate the fields of a structure are given below.
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
448
11537
a4b0e292107f Add undocumented function nfields to documentation.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
449 @DOCSTRING(nfields)
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
450
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
451 @DOCSTRING(fieldnames)
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
452
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
453 @DOCSTRING(isfield)
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
454
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
455 @DOCSTRING(getfield)
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
456
11537
a4b0e292107f Add undocumented function nfields to documentation.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
457 @DOCSTRING(setfield)
a4b0e292107f Add undocumented function nfields to documentation.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
458
a4b0e292107f Add undocumented function nfields to documentation.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
459 @DOCSTRING(rmfield)
a4b0e292107f Add undocumented function nfields to documentation.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
460
a4b0e292107f Add undocumented function nfields to documentation.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
461 @DOCSTRING(orderfields)
a4b0e292107f Add undocumented function nfields to documentation.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
462
6863
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents: 6839
diff changeset
463 @DOCSTRING(substruct)
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents: 6839
diff changeset
464
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents: 6839
diff changeset
465 @node Processing Data in Structures
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents: 6839
diff changeset
466 @subsection Processing Data in Structures
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
467
6939
46d1ad37d943 [project @ 2007-10-01 16:12:20 by jwe]
jwe
parents: 6868
diff changeset
468 The simplest way to process data in a structure is within a @code{for}
9036
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
469 loop (@pxref{Looping Over Structure Elements}). A similar effect can be
6863
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents: 6839
diff changeset
470 achieved with the @code{structfun} function, where a user defined
6939
46d1ad37d943 [project @ 2007-10-01 16:12:20 by jwe]
jwe
parents: 6868
diff changeset
471 function is applied to each field of the structure.
6863
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents: 6839
diff changeset
472
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents: 6839
diff changeset
473 @DOCSTRING(structfun)
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents: 6839
diff changeset
474
6939
46d1ad37d943 [project @ 2007-10-01 16:12:20 by jwe]
jwe
parents: 6868
diff changeset
475 Alternatively, to process the data in a structure, the structure might
6863
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents: 6839
diff changeset
476 be converted to another type of container before being treated.
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents: 6839
diff changeset
477
3c64128e621c [project @ 2007-09-05 07:52:48 by dbateman]
dbateman
parents: 6839
diff changeset
478 @DOCSTRING(struct2cell)
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
479
6517
a1ec359aef37 [project @ 2007-04-11 15:14:48 by jwe]
jwe
parents: 6516
diff changeset
480 @node Cell Arrays
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
481 @section Cell Arrays
3439
3234a698073a [project @ 2000-01-14 09:51:14 by jwe]
jwe
parents:
diff changeset
482 @cindex cell arrays
3234a698073a [project @ 2000-01-14 09:51:14 by jwe]
jwe
parents:
diff changeset
483
6514
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
484 It can be both necessary and convenient to store several variables of
9036
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
485 different size or type in one variable. A cell array is a container
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
486 class able to do just that. In general cell arrays work just like
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
487 @math{N}-dimensional arrays with the exception of the use of @samp{@{}
6514
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
488 and @samp{@}} as allocation and indexing operators.
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
489
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
490 @menu
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
491 * Basic Usage of Cell Arrays::
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
492 * Creating Cell Arrays::
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
493 * Indexing Cell Arrays::
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
494 * Cell Arrays of Strings::
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
495 * Processing Data in Cell Arrays::
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
496 @end menu
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
497
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
498 @node Basic Usage of Cell Arrays
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
499 @subsection Basic Usage of Cell Arrays
12175
2090995ca588 Correct en-dash,em-dash instances in docstrings.
Rik <octave@nomad.inbox5.com>
parents: 11537
diff changeset
500 @opindex @{
2090995ca588 Correct en-dash,em-dash instances in docstrings.
Rik <octave@nomad.inbox5.com>
parents: 11537
diff changeset
501 @opindex @}
6514
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
502 As an example, the following code creates a cell array containing a
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
503 string and a 2-by-2 random matrix
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
504
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
505 @example
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
506 c = @{"a string", rand(2, 2)@};
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
507 @end example
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
508
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
509 @noindent
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
510 To access the elements of a cell array, it can be indexed with the @{
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
511 and @} operators. Thus, the variable created in the previous example
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
512 can be indexed like this:
6514
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
513
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
514 @example
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
515 @group
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
516 c@{1@}
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
517 @result{} ans = a string
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
518 @end group
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
519 @end example
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
520
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
521 @noindent
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
522 As with numerical arrays several elements of a cell array can be
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
523 extracted by indexing with a vector of indexes
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
524
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
525 @example
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
526 @group
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
527 c@{1:2@}
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
528 @result{} ans =
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
529
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
530 (,
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
531 [1] = a string
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
532 [2] =
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
533
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
534 0.593993 0.627732
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
535 0.377037 0.033643
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
536
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
537 ,)
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
538 @end group
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
539 @end example
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
540
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
541 The indexing operators can also be used to insert or overwrite elements
9036
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
542 of a cell array. The following code inserts the scalar 3 on the
6514
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
543 third place of the previously created cell array
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
544
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
545 @example
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
546 @group
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
547 c@{3@} = 3
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
548 @result{} c =
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
549
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
550 @{
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
551 [1,1] = a string
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
552 [1,2] =
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
553
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
554 0.593993 0.627732
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
555 0.377037 0.033643
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
556
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
557 [1,3] = 3
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
558 @}
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
559 @end group
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
560 @end example
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
561
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
562 Details on indexing cell arrays are explained in @ref{Indexing Cell Arrays}.
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
563
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
564 In general nested cell arrays are displayed hierarchically as in the
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
565 previous example. In some circumstances it makes sense to reference
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
566 them by their index, and this can be performed by the @code{celldisp}
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
567 function.
6868
975fcdfb0d2d [project @ 2007-09-06 16:34:29 by dbateman]
dbateman
parents: 6863
diff changeset
568
975fcdfb0d2d [project @ 2007-09-06 16:34:29 by dbateman]
dbateman
parents: 6863
diff changeset
569 @DOCSTRING(celldisp)
975fcdfb0d2d [project @ 2007-09-06 16:34:29 by dbateman]
dbateman
parents: 6863
diff changeset
570
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
571 To test if an object is a cell array, use the @code{iscell}
9758
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9312
diff changeset
572 function. For example:
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
573
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
574 @example
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
575 @group
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
576 iscell(c)
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
577 @result{} ans = 1
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
578
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
579 iscell(3)
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
580 @result{} ans = 0
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
581
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
582 @end group
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
583 @end example
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
584
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
585 @DOCSTRING(iscell)
6516
ce5caa673642 [project @ 2007-04-11 14:26:39 by jwe]
jwe
parents: 6514
diff changeset
586
6514
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
587 @node Creating Cell Arrays
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
588 @subsection Creating Cell Array
6514
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
589
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
590 The introductory example (@pxref{Basic Usage of Cell Arrays}) showed
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
591 how to create a cell array containing currently available variables.
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
592 In many situations, however, it is useful to create a cell array and
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
593 then fill it with data.
6514
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
594
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
595 The @code{cell} function returns a cell array of a given size, containing
9036
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
596 empty matrices. This function is similar to the @code{zeros}
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
597 function for creating new numerical arrays. The following example creates
6514
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
598 a 2-by-2 cell array containing empty matrices
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
599
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
600 @example
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
601 @group
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
602 c = cell(2,2)
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
603 @result{} c =
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
604
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
605 @{
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
606 [1,1] = [](0x0)
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
607 [2,1] = [](0x0)
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
608 [1,2] = [](0x0)
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
609 [2,2] = [](0x0)
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
610 @}
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
611 @end group
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
612 @end example
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
613
10828
322f43e0e170 Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents: 10122
diff changeset
614 Just like numerical arrays, cell arrays can be multi-dimensional. The
6514
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
615 @code{cell} function accepts any number of positive integers to describe
9036
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
616 the size of the returned cell array. It is also possible to set the size
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
617 of the cell array through a vector of positive integers. In the
8347
fa78cb8d8a5c corrections for typos
Brian Gough<bjg@network-theory.co.uk>
parents: 8176
diff changeset
618 following example two cell arrays of equal size are created, and the size
6514
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
619 of the first one is displayed
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
620
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
621 @example
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9036
diff changeset
622 @group
6514
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
623 c1 = cell(3, 4, 5);
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
624 c2 = cell( [3, 4, 5] );
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
625 size(c1)
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
626 @result{} ans =
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
627 3 4 5
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9036
diff changeset
628 @end group
6514
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
629 @end example
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
630
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
631 @noindent
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
632 As can be seen, the @ref{doc-size, @code{size}} function also works
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
633 for cell arrays. As do other functions describing the size of an
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
634 object, such as @ref{doc-length, @code{length}}, @ref{doc-numel,
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
635 @code{numel}}, @ref{doc-rows, @code{rows}}, and @ref{doc-columns,
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
636 @code{columns}}.
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
637
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
638 @DOCSTRING(cell)
6514
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
639
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9036
diff changeset
640 As an alternative to creating empty cell arrays, and then filling them, it
6514
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
641 is possible to convert numerical arrays into cell arrays using the
10122
9d1a14e12431 Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9758
diff changeset
642 @code{num2cell}, @code{mat2cell} and @code{cellslices} functions.
6514
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
643
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
644 @DOCSTRING(num2cell)
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
645
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
646 @DOCSTRING(mat2cell)
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
647
10122
9d1a14e12431 Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9758
diff changeset
648 @DOCSTRING(cellslices)
9d1a14e12431 Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9758
diff changeset
649
6514
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
650 @node Indexing Cell Arrays
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
651 @subsection Indexing Cell Arrays
6514
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
652
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
653 As shown in @pxref{Basic Usage of Cell Arrays} elements can be
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
654 extracted from cell arrays using the @samp{@{} and @samp{@}}
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
655 operators. If you want to extract or access subarrays which are still
9758
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9312
diff changeset
656 cell arrays, you need to use the @samp{(} and @samp{)} operators. The
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
657 following example illustrates the difference:
6514
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
658
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
659 @example
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
660 @group
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
661 c = @{"1", "2", "3"; "a", "b", "c"; "4", "5", "6"@};
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
662 c@{2,3@}
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
663 @result{} ans = c
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
664
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
665 c(2,3)
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
666 @result{} ans =
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
667 @{
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
668 [1,1] = c
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
669 @}
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
670 @end group
6514
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
671 @end example
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
672
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
673 @noindent So with @samp{@{@}} you access elements of a cell
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
674 array, while with @samp{()} you access a sub array of a cell
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
675 array.
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
676
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
677 Using the @samp{(} and @samp{)} operators, indexing works for cell
10828
322f43e0e170 Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents: 10122
diff changeset
678 arrays like for multi-dimensional arrays. As an example, all the rows
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
679 of the first and third column of a cell array can be set to @code{0}
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
680 with the following command:
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
681
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
682 @example
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
683 @group
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
684 c(:, [1, 3]) = @{0@}
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
685 @result{} =
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
686 @{
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
687 [1,1] = 0
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
688 [2,1] = 0
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
689 [3,1] = 0
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
690 [1,2] = 2
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
691 [2,2] = 10
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
692 [3,2] = 20
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
693 [1,3] = 0
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
694 [2,3] = 0
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
695 [3,3] = 0
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
696 @}
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
697 @end group
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
698 @end example
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
699
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
700 Note, that the above can also be achieved like this:
6514
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
701
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
702 @example
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
703 c(:, [1, 3]) = 0;
6514
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
704 @end example
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
705
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
706 @noindent Here, the scalar @samp{0} is automatically promoted to
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
707 cell array @samp{@{0@}} and then assigned to the subarray of @code{c}.
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
708
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
709 To give another example for indexing cell arrays with @samp{()}, you
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
710 can exchange the first and the second row of a cell array as in the
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
711 following command:
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
712
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
713 @example
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
714 @group
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
715 c = @{1, 2, 3; 4, 5, 6@};
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
716 c([1, 2], :) = c([2, 1], :)
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
717 @result{} =
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
718 @{
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
719 [1,1] = 4
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
720 [2,1] = 1
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
721 [1,2] = 5
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
722 [2,2] = 2
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
723 [1,3] = 6
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
724 [2,3] = 3
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
725 @}
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
726 @end group
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
727 @end example
6514
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
728
6518
952c8b00525e [project @ 2007-04-11 20:50:22 by jwe]
jwe
parents: 6517
diff changeset
729 Accessing multiple elements of a cell array with the @samp{@{} and
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
730 @samp{@}} operators will result in a comma-separated list of all the
9758
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9312
diff changeset
731 requested elements (@pxref{Comma Separated Lists}). Using the
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
732 @samp{@{} and @samp{@}} operators the first two rows in the above
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
733 example can be swapped back like this:
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
734
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
735 @example
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
736 @group
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
737 [c@{[1,2], :@}] = deal(c@{[2, 1], :@})
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
738 @result{} =
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
739 @{
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
740 [1,1] = 1
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
741 [2,1] = 4
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
742 [1,2] = 2
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
743 [2,2] = 5
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
744 [1,3] = 3
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
745 [2,3] = 6
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
746 @}
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
747 @end group
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
748 @end example
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
749
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
750 As for struct arrays and numerical arrays, the empty matrix @samp{[]}
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
751 can be used to delete elements from a cell array:
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
752
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
753 @example
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
754 @group
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
755 x = @{"1", "2"; "3", "4"@};
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
756 x(1, :) = []
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
757 @result{} x =
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
758 @{
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
759 [1,1] = 3
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
760 [1,2] = 4
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
761 @}
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
762 @end group
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
763 @end example
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
764
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
765 The following example shows how to just remove the contents of cell
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
766 array elements but not delete the space for them:
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
767
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
768 @example
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
769 @group
7031
120f3135952f [project @ 2007-10-15 15:30:03 by jwe]
jwe
parents: 7025
diff changeset
770 x = @{"1", "2"; "3", "4"@};
6839
40ad39648884 [project @ 2007-08-28 15:28:13 by dbateman]
dbateman
parents: 6837
diff changeset
771 x@{1, :@} = []
40ad39648884 [project @ 2007-08-28 15:28:13 by dbateman]
dbateman
parents: 6837
diff changeset
772 @result{} x =
40ad39648884 [project @ 2007-08-28 15:28:13 by dbateman]
dbateman
parents: 6837
diff changeset
773 @{
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
774 [1,1] = [](0x0)
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
775 [2,1] = 3
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
776 [1,2] = [](0x0)
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
777 [2,2] = 4
6839
40ad39648884 [project @ 2007-08-28 15:28:13 by dbateman]
dbateman
parents: 6837
diff changeset
778 @}
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
779 @end group
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
780 @end example
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
781
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
782 @node Cell Arrays of Strings
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
783 @subsection Cell Arrays of Strings
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
784
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
785 One common use of cell arrays is to store multiple strings in the same
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
786 variable. It is also possible to store multiple strings in a
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
787 character matrix by letting each row be a string. This, however,
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
788 introduces the problem that all strings must be of equal length.
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
789 Therefore, it is recommended to use cell arrays to store multiple
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
790 strings. For cases, where the character matrix representation is required
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
791 for an operation, there are several functions that convert a cell
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
792 array of strings to a character array and back. @code{char} and
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
793 @code{strvcat} convert cell arrays to a character array
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
794 (@pxref{Concatenating Strings}), while the function @code{cellstr}
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
795 converts a character array to a cell array of strings:
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
796
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
797 @example
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9036
diff changeset
798 @group
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
799 a = ["hello"; "world"];
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
800 c = cellstr (a)
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
801 @result{} c =
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
802 @{
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
803 [1,1] = hello
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
804 [2,1] = world
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
805 @}
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9036
diff changeset
806 @end group
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
807 @end example
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
808
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
809 @DOCSTRING(cellstr)
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
810
8828
8463d1a2e544 Doc fixes.
Brian Gough <bjg@network-theory.co.uk>
parents: 8584
diff changeset
811 One further advantage of using cell arrays to store multiple strings is
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
812 that most functions for string manipulations included with Octave
9036
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
813 support this representation. As an example, it is possible to compare
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
814 one string with many others using the @code{strcmp} function. If one of
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
815 the arguments to this function is a string and the other is a cell array
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
816 of strings, each element of the cell array will be compared to the string
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
817 argument:
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
818
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
819 @example
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9036
diff changeset
820 @group
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
821 c = @{"hello", "world"@};
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
822 strcmp ("hello", c)
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
823 @result{} ans =
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
824 1 0
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9036
diff changeset
825 @end group
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
826 @end example
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
827
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
828 @noindent
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
829 The following string functions support cell arrays of strings:
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
830 @code{char}, @code{strvcat}, @code{strcat} (@pxref{Concatenating
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
831 Strings}), @code{strcmp}, @code{strncmp}, @code{strcmpi},
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
832 @code{strncmpi} (@pxref{Comparing Strings}), @code{str2double},
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
833 @code{deblank}, @code{strtrim}, @code{strtrunc}, @code{strfind},
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
834 @code{strmatch}, , @code{regexp}, @code{regexpi} (@pxref{Manipulating
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
835 Strings}) and @code{str2double} (@pxref{String Conversions}).
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
836
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
837 The function @code{iscellstr} can be used to test if an object is a
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
838 cell array of strings.
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
839
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
840 @DOCSTRING(iscellstr)
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
841
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
842 @node Processing Data in Cell Arrays
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
843 @subsection Processing Data in Cell Arrays
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
844
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
845 Data that is stored in a cell array can be processed in several ways
9036
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
846 depending on the actual data. The simplest way to process that data
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
847 is to iterate through it using one or more @code{for} loops. The same
8828
8463d1a2e544 Doc fixes.
Brian Gough <bjg@network-theory.co.uk>
parents: 8584
diff changeset
848 idea can be implemented more easily through the use of the @code{cellfun}
8493
2f5a2c58c15e [docs] user specified => user-specified
Brian Gough <bjg@gnu.org>
parents: 8372
diff changeset
849 function that calls a user-specified function on all elements of a cell
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
850 array.
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
851
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
852 @DOCSTRING(cellfun)
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
853
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
854 An alternative is to convert the data to a different container, such as
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
855 a matrix or a data structure. Depending on the data this is possible
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
856 using the @code{cell2mat} and @code{cell2struct} functions.
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
857
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
858 @DOCSTRING(cell2mat)
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
859
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
860 @DOCSTRING(cell2struct)
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
861
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
862 @node Comma Separated Lists
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
863 @section Comma Separated Lists
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
864 @cindex comma separated lists
8541
d2cf983bdc9d container.txi: define cs-list
John W. Eaton <jwe@octave.org>
parents: 8493
diff changeset
865 @cindex cs-lists
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
866
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
867 Comma separated lists @footnote{Comma-separated lists are also sometimes
8541
d2cf983bdc9d container.txi: define cs-list
John W. Eaton <jwe@octave.org>
parents: 8493
diff changeset
868 informally referred to as @dfn{cs-lists}.} are the basic argument type
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
869 to all Octave functions - both for input and return arguments. In the
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
870 example
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
871
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
872 @example
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
873 max (@var{a}, @var{b})
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
874 @end example
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
875
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
876 @noindent
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
877 @samp{@var{a}, @var{b}} is a comma separated list. Comma separated lists
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
878 can appear on both the right and left hand side of an assignment. For
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
879 example
6514
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
880
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
881 @example
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9036
diff changeset
882 @group
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
883 x = [1 0 1 0 0 1 1; 0 0 0 0 0 0 7];
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
884 [@var{i}, @var{j}] = find (@var{x}, 2, "last");
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
885 @end group
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
886 @end example
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
887
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
888 @noindent
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
889 Here, @samp{@var{x}, 2, "last"} is a comma separated list constituting
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
890 the input arguments of @code{find}. @code{find} returns a comma
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
891 separated list of output arguments which is assigned element by
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
892 element to the comma separated list @samp{@var{i}, @var{j}}.
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
893
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
894 Another example of where comma separated lists are used is in the
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
895 creation of a new array with @code{[]} (@pxref{Matrices}) or the
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
896 creation of a cell array with @code{@{@}} (@pxref{Basic Usage of Cell
9758
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9312
diff changeset
897 Arrays}). In the expressions
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
898
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
899 @example
9758
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9312
diff changeset
900 @group
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
901 a = [1, 2, 3, 4];
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
902 c = @{4, 5, 6, 7@};
9758
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9312
diff changeset
903 @end group
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
904 @end example
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
905
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
906 @noindent
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
907 both @samp{1, 2, 3, 4} and @samp{4, 5, 6, 7} are comma separated lists.
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
908
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
909 Comma separated lists cannot be directly manipulated by the
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
910 user. However, both structure arrays and cell arrays can be converted
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
911 into comma separated lists, and thus used in place of explicitly
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
912 written comma separated lists. This feature is useful in many ways,
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
913 as will be shown in the following subsections.
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
914
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
915 @menu
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
916 * Comma Separated Lists Generated from Cell Arrays::
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
917 * Comma Separated Lists Generated from Structure Arrays::
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
918 @end menu
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
919
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
920 @node Comma Separated Lists Generated from Cell Arrays
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
921 @subsection Comma Separated Lists Generated from Cell Arrays
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
922
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
923 As has been mentioned above (@pxref{Indexing Cell Arrays}), elements
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
924 of a cell array can be extracted into a comma separated list with the
9758
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9312
diff changeset
925 @code{@{} and @code{@}} operators. By surrounding this list with
09da0bd91412 Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents: 9312
diff changeset
926 @code{[} and @code{]}, it can be concatenated into an array. For example:
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
927
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
928 @example
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
929 @group
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
930 a = @{1, [2, 3], 4, 5, 6@};
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
931 b = [a@{1:4@}]
6514
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
932 @result{} b =
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
933 1 2 3 4
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9036
diff changeset
934 @end group
6514
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
935 @end example
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
936
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
937 Similarly, it is possible to create a new cell array containing cell
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
938 elements selected with @code{@{@}}. By surrounding the list with
8828
8463d1a2e544 Doc fixes.
Brian Gough <bjg@network-theory.co.uk>
parents: 8584
diff changeset
939 @samp{@{} and @samp{@}} a new cell array will be created, as the
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
940 following example illustrates:
6514
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
941
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
942 @example
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9036
diff changeset
943 @group
6514
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
944 a = @{1, rand(2, 2), "three"@};
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
945 b = @{ a@{ [1, 3] @} @}
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
946 @result{} b =
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
947 @{
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
948 [1,1] = 1
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
949 [1,2] = three
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
950 @}
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9036
diff changeset
951 @end group
6514
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
952 @end example
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
953
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
954 Furthermore, cell elements (accessed by @code{@{@}}) can be passed
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
955 directly to a function. The list of elements from the cell array will
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
956 be passed as an argument list to a given function as if it is called
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
957 with the elements as individual arguments. The two calls to
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
958 @code{printf} in the following example are identical but the latter is
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
959 simpler and can handle cell arrays of an arbitrary size:
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
960
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
961 @example
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
962 @group
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
963 c = @{"GNU", "Octave", "is", "Free", "Software"@};
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
964 printf ("%s ", c@{1@}, c@{2@}, c@{3@}, c@{4@}, c@{5@});
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
965 @print{} GNU Octave is Free Software
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
966 printf ("%s ", c@{:@});
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
967 @print{} GNU Octave is Free Software
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
968 @end group
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
969 @end example
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
970
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
971 If used on the left-hand side of an assignment, a comma separated list
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
972 generated with @code{@{@}} can be assigned to. An example is
6514
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
973
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
974 @example
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9036
diff changeset
975 @group
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
976 in@{1@} = [10, 20, 30, 40, 50, 60, 70, 80, 90];
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
977 in@{2@} = inf;
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
978 in@{3@} = "last";
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
979 in@{4@} = "first";
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
980 out = cell (4, 1);
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
981 [out@{1:3@}] = find (in@{1 : 3@});
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
982 [out@{4:6@}] = find (in@{[1, 2, 4]@})
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
983 @result{} out =
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
984 @{
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
985 [1,1] = 1
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
986 [2,1] = 9
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
987 [3,1] = 90
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
988 [4,1] = 1
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
989 [3,1] = 1
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
990 [4,1] = 10
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
991 @}
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9036
diff changeset
992 @end group
6514
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
993 @end example
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
994
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
995
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
996 @node Comma Separated Lists Generated from Structure Arrays
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
997 @subsection Comma Separated Lists Generated from Structure Arrays
6939
46d1ad37d943 [project @ 2007-10-01 16:12:20 by jwe]
jwe
parents: 6868
diff changeset
998 Structure arrays can equally be used to create comma separated
9036
58604c45ca74 Cleanup of data types related documentation
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
999 lists. This is done by addressing one of the fields of a structure
10828
322f43e0e170 Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents: 10122
diff changeset
1000 array. For example:
6514
5ef6f71974db [project @ 2007-04-11 14:15:40 by jwe]
jwe
parents: 6502
diff changeset
1001
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
1002 @example
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
1003 @group
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
1004 x = ceil (randn (10, 1));
9312
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
1005 in = struct ("call1", @{x, 3, "last"@},
0f7480d07f6a update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9209
diff changeset
1006 "call2", @{x, inf, "first"@});
7031
120f3135952f [project @ 2007-10-15 15:30:03 by jwe]
jwe
parents: 7025
diff changeset
1007 out = struct ("call1", cell (2, 1), "call2", cell (2, 1));
6837
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
1008 [out.call1] = find (in.call1);
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
1009 [out.call2] = find (in.call2);
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
1010 @end group
7eefeed173ea [project @ 2007-08-27 20:20:55 by dbateman]
dbateman
parents: 6778
diff changeset
1011 @end example