Mercurial > octave-nkf
annotate doc/interpreter/container.txi @ 17281:bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Macro handles options ("on") or properties ("position") more elegantly
than @code{"text"}.
* doc/interpreter/macros.texi: Add new @qcode macro.
* doc/interpreter/tips.txi: Add documentation about @qcode macro.
* doc/interpreter/basics.txi, doc/interpreter/container.txi,
doc/interpreter/emacs.txi, doc/interpreter/errors.txi,
doc/interpreter/eval.txi, doc/interpreter/expr.txi,
doc/interpreter/external.txi, doc/interpreter/func.txi,
doc/interpreter/grammar.txi, doc/interpreter/image.txi,
doc/interpreter/install.txi, doc/interpreter/interp.txi,
doc/interpreter/io.txi, doc/interpreter/matrix.txi,
doc/interpreter/numbers.txi, doc/interpreter/oop.txi,
doc/interpreter/package.txi, doc/interpreter/plot.txi,
doc/interpreter/quad.txi, doc/interpreter/sparse.txi,
doc/interpreter/strings.txi, doc/interpreter/system.txi,
doc/interpreter/vectorize.txi, libinterp/corefcn/balance.cc,
libinterp/corefcn/bitfcns.cc, libinterp/corefcn/cellfun.cc,
libinterp/corefcn/conv2.cc, libinterp/corefcn/data.cc,
libinterp/corefcn/debug.cc, libinterp/corefcn/defaults.cc,
libinterp/corefcn/dirfns.cc, libinterp/corefcn/dlmread.cc,
libinterp/corefcn/error.cc, libinterp/corefcn/file-io.cc,
libinterp/corefcn/find.cc, libinterp/corefcn/gammainc.cc,
libinterp/corefcn/graphics.cc, libinterp/corefcn/help.cc,
libinterp/corefcn/hex2num.cc, libinterp/corefcn/input.cc,
libinterp/corefcn/load-path.cc, libinterp/corefcn/load-save.cc,
libinterp/corefcn/ls-oct-ascii.cc, libinterp/corefcn/lu.cc,
libinterp/corefcn/luinc.cc, libinterp/corefcn/matrix_type.cc,
libinterp/corefcn/oct-hist.cc, libinterp/corefcn/pager.cc,
libinterp/corefcn/pr-output.cc, libinterp/corefcn/pt-jit.cc,
libinterp/corefcn/qz.cc, libinterp/corefcn/rand.cc,
libinterp/corefcn/regexp.cc, libinterp/corefcn/schur.cc,
libinterp/corefcn/sighandlers.cc, libinterp/corefcn/sparse.cc,
libinterp/corefcn/spparms.cc, libinterp/corefcn/str2double.cc,
libinterp/corefcn/svd.cc, libinterp/corefcn/symtab.cc,
libinterp/corefcn/syscalls.cc, libinterp/corefcn/toplev.cc,
libinterp/corefcn/tril.cc, libinterp/corefcn/typecast.cc,
libinterp/corefcn/utils.cc, libinterp/corefcn/variables.cc,
libinterp/dldfcn/__init_fltk__.cc, libinterp/dldfcn/chol.cc,
libinterp/dldfcn/colamd.cc, libinterp/dldfcn/fftw.cc, libinterp/dldfcn/qr.cc,
libinterp/dldfcn/symbfact.cc, libinterp/octave-value/ov-base.cc,
libinterp/octave-value/ov-fcn-handle.cc,
libinterp/octave-value/ov-fcn-inline.cc, libinterp/octave-value/ov-java.cc,
libinterp/octave-value/ov-range.cc, libinterp/octave-value/ov-struct.cc,
libinterp/octave-value/ov-usr-fcn.cc, libinterp/parse-tree/oct-parse.in.yy,
libinterp/parse-tree/pt-binop.cc, libinterp/parse-tree/pt-eval.cc,
libinterp/parse-tree/pt-mat.cc, scripts/@ftp/ftp.m,
scripts/deprecated/java_convert_matrix.m, scripts/deprecated/java_debug.m,
scripts/deprecated/java_unsigned_conversion.m, scripts/deprecated/shell_cmd.m,
scripts/general/dblquad.m, scripts/general/display.m,
scripts/general/genvarname.m, scripts/general/idivide.m,
scripts/general/interp1.m, scripts/general/interp2.m,
scripts/general/interp3.m, scripts/general/interpn.m, scripts/general/isa.m,
scripts/general/profexplore.m, scripts/general/profile.m,
scripts/general/quadgk.m, scripts/general/randi.m, scripts/general/structfun.m,
scripts/general/subsindex.m, scripts/general/triplequad.m,
scripts/geometry/griddata.m, scripts/geometry/griddata3.m,
scripts/geometry/griddatan.m, scripts/geometry/voronoi.m, scripts/help/help.m,
scripts/help/lookfor.m, scripts/image/cmpermute.m, scripts/image/colormap.m,
scripts/image/image.m, scripts/image/imagesc.m, scripts/image/imfinfo.m,
scripts/image/imformats.m, scripts/image/imread.m, scripts/image/imshow.m,
scripts/image/imwrite.m, scripts/image/ind2gray.m, scripts/image/lines.m,
scripts/image/rgb2ind.m, scripts/image/spinmap.m, scripts/io/dlmwrite.m,
scripts/io/strread.m, scripts/io/textread.m, scripts/io/textscan.m,
scripts/java/javaclasspath.m, scripts/java/usejava.m,
scripts/miscellaneous/bzip2.m, scripts/miscellaneous/computer.m,
scripts/miscellaneous/copyfile.m, scripts/miscellaneous/debug.m,
scripts/miscellaneous/dos.m, scripts/miscellaneous/edit.m,
scripts/miscellaneous/gzip.m, scripts/miscellaneous/license.m,
scripts/miscellaneous/mkoctfile.m, scripts/miscellaneous/movefile.m,
scripts/miscellaneous/parseparams.m, scripts/miscellaneous/unix.m,
scripts/optimization/fminbnd.m, scripts/optimization/fminsearch.m,
scripts/optimization/fminunc.m, scripts/optimization/fsolve.m,
scripts/optimization/fzero.m, scripts/optimization/glpk.m,
scripts/optimization/lsqnonneg.m, scripts/optimization/optimset.m,
scripts/optimization/pqpnonneg.m, scripts/pkg/pkg.m, scripts/plot/allchild.m,
scripts/plot/ancestor.m, scripts/plot/area.m, scripts/plot/axis.m,
scripts/plot/bar.m, scripts/plot/barh.m, scripts/plot/box.m,
scripts/plot/caxis.m, scripts/plot/cla.m, scripts/plot/clabel.m,
scripts/plot/clf.m, scripts/plot/close.m, scripts/plot/colorbar.m,
scripts/plot/daspect.m, scripts/plot/ezmesh.m, scripts/plot/ezmeshc.m,
scripts/plot/ezsurf.m, scripts/plot/ezsurfc.m, scripts/plot/findall.m,
scripts/plot/findobj.m, scripts/plot/gcbo.m, scripts/plot/gcf.m,
scripts/plot/gco.m, scripts/plot/grid.m, scripts/plot/guihandles.m,
scripts/plot/hdl2struct.m, scripts/plot/hidden.m, scripts/plot/hold.m,
scripts/plot/isonormals.m, scripts/plot/isosurface.m, scripts/plot/legend.m,
scripts/plot/mesh.m, scripts/plot/meshc.m, scripts/plot/meshz.m,
scripts/plot/newplot.m, scripts/plot/orient.m, scripts/plot/pareto.m,
scripts/plot/patch.m, scripts/plot/pbaspect.m, scripts/plot/pcolor.m,
scripts/plot/plot.m, scripts/plot/print.m,
scripts/plot/private/__add_default_menu__.m, scripts/plot/quiver.m,
scripts/plot/quiver3.m, scripts/plot/refreshdata.m, scripts/plot/saveas.m,
scripts/plot/scatter.m, scripts/plot/scatter3.m, scripts/plot/shading.m,
scripts/plot/shrinkfaces.m, scripts/plot/slice.m, scripts/plot/stem.m,
scripts/plot/stem3.m, scripts/plot/struct2hdl.m, scripts/plot/subplot.m,
scripts/plot/surf.m, scripts/plot/surfc.m, scripts/plot/surfl.m,
scripts/plot/tetramesh.m, scripts/plot/uigetfile.m, scripts/plot/uimenu.m,
scripts/plot/uiputfile.m, scripts/plot/waterfall.m, scripts/plot/whitebg.m,
scripts/plot/xlim.m, scripts/plot/ylim.m, scripts/plot/zlim.m,
scripts/polynomial/conv.m, scripts/polynomial/polyout.m,
scripts/polynomial/splinefit.m, scripts/set/ismember.m, scripts/set/powerset.m,
scripts/set/setdiff.m, scripts/set/union.m, scripts/set/unique.m,
scripts/signal/detrend.m, scripts/signal/filter2.m, scripts/signal/freqz.m,
scripts/signal/periodogram.m, scripts/signal/spectral_adf.m,
scripts/signal/spectral_xdf.m, scripts/sparse/eigs.m, scripts/sparse/svds.m,
scripts/specfun/legendre.m, scripts/special-matrix/gallery.m,
scripts/statistics/base/mean.m, scripts/statistics/base/moment.m,
scripts/statistics/tests/cor_test.m,
scripts/statistics/tests/kolmogorov_smirnov_test.m,
scripts/statistics/tests/kolmogorov_smirnov_test_2.m,
scripts/statistics/tests/kruskal_wallis_test.m,
scripts/statistics/tests/prop_test_2.m, scripts/statistics/tests/sign_test.m,
scripts/statistics/tests/t_test.m, scripts/statistics/tests/t_test_2.m,
scripts/statistics/tests/t_test_regression.m,
scripts/statistics/tests/u_test.m, scripts/statistics/tests/var_test.m,
scripts/statistics/tests/welch_test.m,
scripts/statistics/tests/wilcoxon_test.m, scripts/statistics/tests/z_test.m,
scripts/statistics/tests/z_test_2.m, scripts/strings/base2dec.m,
scripts/strings/index.m, scripts/strings/isstrprop.m,
scripts/strings/mat2str.m, scripts/strings/regexptranslate.m,
scripts/strings/rindex.m, scripts/strings/str2num.m, scripts/strings/strcat.m,
scripts/strings/strjust.m, scripts/strings/strmatch.m,
scripts/strings/validatestring.m, scripts/testfun/demo.m,
scripts/testfun/example.m, scripts/testfun/test.m, scripts/time/addtodate.m,
scripts/time/asctime.m, scripts/time/datestr.m, scripts/time/datetick.m,
scripts/time/weekday.m, scripts/ui/errordlg.m, scripts/ui/helpdlg.m,
scripts/ui/inputdlg.m, scripts/ui/listdlg.m, scripts/ui/msgbox.m,
scripts/ui/questdlg.m, scripts/ui/warndlg.m: Use new @qcode macro.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 19 Aug 2013 20:46:38 -0700 |
parents | f2a8592b8fbd |
children | d63878346099 |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
14119
diff
changeset
|
1 @c Copyright (C) 1996-2012 John W. Eaton |
7018 | 2 @c |
3 @c This file is part of Octave. | |
4 @c | |
5 @c Octave is free software; you can redistribute it and/or modify it | |
6 @c under the terms of the GNU General Public License as published by the | |
7 @c Free Software Foundation; either version 3 of the License, or (at | |
8 @c your option) any later version. | |
9 @c | |
10 @c Octave is distributed in the hope that it will be useful, but WITHOUT | |
11 @c ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
12 @c FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
13 @c for more details. | |
14 @c | |
15 @c You should have received a copy of the GNU General Public License | |
16 @c along with Octave; see the file COPYING. If not, see | |
17 @c <http://www.gnu.org/licenses/>. | |
3439 | 18 |
6837 | 19 @node Data Containers |
20 @chapter Data Containers | |
21 @cindex containers | |
22 | |
6939 | 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 | 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 | 29 |
30 @menu | |
12596
5161d02c96b7
doc: Add help text for dynamic naming "(var)" of structure fields.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
31 * Structures:: |
6837 | 32 * Cell Arrays:: |
33 * Comma Separated Lists:: | |
34 @end menu | |
35 | |
12596
5161d02c96b7
doc: Add help text for dynamic naming "(var)" of structure fields.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
36 @node Structures |
5161d02c96b7
doc: Add help text for dynamic naming "(var)" of structure fields.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
37 @section Structures |
6837 | 38 @cindex structures |
39 @cindex data structures | |
40 | |
16816
12005245b645
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
16772
diff
changeset
|
41 Octave includes support for organizing data in structures. The current |
6837 | 42 implementation uses an associative array with indices limited to |
15615
808e4f13e220
doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14856
diff
changeset
|
43 strings, but the syntax is more like C-style structures. |
9312
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 | 57 |
58 Elements of structures can be of any value type. For example, the three | |
59 expressions | |
60 | |
61 @example | |
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 | 66 @end group |
67 @end example | |
68 | |
12175
2090995ca588
Correct en-dash,em-dash instances in docstrings.
Rik <octave@nomad.inbox5.com>
parents:
11537
diff
changeset
|
69 @opindex . |
6837 | 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 | 75 |
76 @example | |
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 | 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 | 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 | 89 @end group |
90 @end example | |
91 | |
92 @noindent | |
93 Note that Octave may print the elements in any order. | |
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 | 96 |
97 @example | |
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 | 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 | 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 | 110 @end group |
111 @end example | |
112 | |
113 Since structures are themselves values, structure elements may reference | |
114 other structures. The following statements change the value of the | |
115 element @code{b} of the structure @code{x} to be a data structure | |
116 containing the single element @code{d}, which has a value of 3. | |
117 | |
118 @example | |
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 | 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 | 138 @end group |
139 @end example | |
140 | |
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 | 143 |
144 @example | |
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 | 160 @end group |
161 @end example | |
162 | |
163 @noindent | |
164 This prevents long and confusing output from large deeply nested | |
11474 | 165 structures. The number of levels to print for nested structures may be |
166 set with the function @code{struct_levels_to_print}, and the function | |
167 @code{print_struct_array_contents} may be used to enable printing of the | |
168 contents of structure arrays. | |
6837 | 169 |
170 @DOCSTRING(struct_levels_to_print) | |
171 | |
11474 | 172 @DOCSTRING(print_struct_array_contents) |
173 | |
6837 | 174 Functions can return structures. For example, the following function |
175 separates the real and complex parts of a matrix and stores them in two | |
176 elements of the same structure variable. | |
177 | |
178 @example | |
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 | 184 @end group |
185 @end example | |
186 | |
187 When called with a complex-valued argument, @code{f} returns the data | |
188 structure containing the real and imaginary parts of the original | |
189 function argument. | |
190 | |
191 @example | |
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 | 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 | 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 | 205 |
9312
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
206 @} |
6837 | 207 @end group |
208 @end example | |
209 | |
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 | 212 |
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 | 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 | 222 |
9312
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
223 s = |
6837 | 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 | 228 |
9312
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
229 v = |
6837 | 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 | 235 @end example |
236 | |
237 It is also possible to cycle through all the elements of a structure in | |
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 | 240 |
241 @node Structure Arrays | |
242 @subsection Structure Arrays | |
243 | |
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 | 249 |
250 @example | |
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 | 256 @end group |
257 @end example | |
258 | |
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 | 264 |
265 @example | |
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 | 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 | 275 @end group |
276 @end example | |
277 | |
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 | 281 |
282 @example | |
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 | 290 @end group |
291 @end example | |
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 | 296 |
297 @example | |
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 | 303 @end group |
304 @end example | |
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 |
14856
c3fd61c59e9c
maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents:
14733
diff
changeset
|
311 [x.a] = deal ("new string1", "new string2"); |
9312
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); |
14856
c3fd61c59e9c
maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents:
14733
diff
changeset
|
325 [x([1,3]).a] = deal ("other string1", "other string2"); |
9312
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 | 336 the example above |
337 | |
338 @example | |
339 @group | |
14856
c3fd61c59e9c
maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents:
14733
diff
changeset
|
340 size (x) |
9312
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
341 @result{} ans = |
6837 | 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 | 344 @end group |
345 @end example | |
346 | |
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 | 349 example |
350 | |
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 | 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 | 369 @end example |
370 | |
371 @node Creating Structures | |
372 @subsection Creating Structures | |
12596
5161d02c96b7
doc: Add help text for dynamic naming "(var)" of structure fields.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
373 @cindex dynamic naming |
6837 | 374 |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17152
diff
changeset
|
375 Besides the index operator @qcode{"."}, Octave can use dynamic naming |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17152
diff
changeset
|
376 @qcode{"(var)"} or the @code{struct} function to create structures. Dynamic |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17152
diff
changeset
|
377 naming uses the string value of a variable as the field name. For example: |
14038
b0cdd60db5e5
doc: Grammarcheck documentation ahead of 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
12944
diff
changeset
|
378 |
12596
5161d02c96b7
doc: Add help text for dynamic naming "(var)" of structure fields.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
379 @example |
5161d02c96b7
doc: Add help text for dynamic naming "(var)" of structure fields.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
380 @group |
5161d02c96b7
doc: Add help text for dynamic naming "(var)" of structure fields.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
381 a = "field2"; |
5161d02c96b7
doc: Add help text for dynamic naming "(var)" of structure fields.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
382 x.a = 1; |
5161d02c96b7
doc: Add help text for dynamic naming "(var)" of structure fields.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
383 x.(a) = 2; |
5161d02c96b7
doc: Add help text for dynamic naming "(var)" of structure fields.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
384 x |
5161d02c96b7
doc: Add help text for dynamic naming "(var)" of structure fields.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
385 @result{} x = |
5161d02c96b7
doc: Add help text for dynamic naming "(var)" of structure fields.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
386 @{ |
5161d02c96b7
doc: Add help text for dynamic naming "(var)" of structure fields.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
387 a = 1 |
5161d02c96b7
doc: Add help text for dynamic naming "(var)" of structure fields.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
388 field2 = 2 |
5161d02c96b7
doc: Add help text for dynamic naming "(var)" of structure fields.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
389 @} |
5161d02c96b7
doc: Add help text for dynamic naming "(var)" of structure fields.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
390 @end group |
5161d02c96b7
doc: Add help text for dynamic naming "(var)" of structure fields.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
391 @end example |
5161d02c96b7
doc: Add help text for dynamic naming "(var)" of structure fields.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
392 |
15615
808e4f13e220
doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14856
diff
changeset
|
393 @noindent |
808e4f13e220
doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14856
diff
changeset
|
394 Dynamic indexing also allows you to use arbitrary strings, not merely |
16816
12005245b645
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
16772
diff
changeset
|
395 valid Octave identifiers (note that this does not work on @sc{matlab}): |
15615
808e4f13e220
doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14856
diff
changeset
|
396 |
808e4f13e220
doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14856
diff
changeset
|
397 @example |
808e4f13e220
doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14856
diff
changeset
|
398 @group |
808e4f13e220
doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14856
diff
changeset
|
399 a = "long field with spaces (and funny char$)"; |
808e4f13e220
doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14856
diff
changeset
|
400 x.a = 1; |
808e4f13e220
doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14856
diff
changeset
|
401 x.(a) = 2; |
808e4f13e220
doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14856
diff
changeset
|
402 x |
808e4f13e220
doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14856
diff
changeset
|
403 @result{} x = |
808e4f13e220
doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14856
diff
changeset
|
404 @{ |
808e4f13e220
doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14856
diff
changeset
|
405 a = 1 |
808e4f13e220
doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14856
diff
changeset
|
406 long field with spaces (and funny char$) = 2 |
808e4f13e220
doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14856
diff
changeset
|
407 @} |
808e4f13e220
doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14856
diff
changeset
|
408 @end group |
808e4f13e220
doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14856
diff
changeset
|
409 @end example |
808e4f13e220
doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14856
diff
changeset
|
410 |
808e4f13e220
doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14856
diff
changeset
|
411 @noindent |
808e4f13e220
doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14856
diff
changeset
|
412 The warning id @code{Octave:matlab-incompatible} can be enabled to warn |
17097
e7a059a9a644
doc: Use XREF as anchor prefix in documentation for clearer results in Info viewer.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
413 about this usage. @xref{XREFwarning_ids,,warning_ids}. |
15615
808e4f13e220
doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14856
diff
changeset
|
414 |
12596
5161d02c96b7
doc: Add help text for dynamic naming "(var)" of structure fields.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
415 More realistically, all of the functions that operate on strings can be used |
5161d02c96b7
doc: Add help text for dynamic naming "(var)" of structure fields.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
416 to build the correct field name before it is entered into the data structure. |
5161d02c96b7
doc: Add help text for dynamic naming "(var)" of structure fields.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
417 |
5161d02c96b7
doc: Add help text for dynamic naming "(var)" of structure fields.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
418 @example |
5161d02c96b7
doc: Add help text for dynamic naming "(var)" of structure fields.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
419 @group |
5161d02c96b7
doc: Add help text for dynamic naming "(var)" of structure fields.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
420 names = ["Bill"; "Mary"; "John"]; |
5161d02c96b7
doc: Add help text for dynamic naming "(var)" of structure fields.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
421 ages = [37; 26; 31]; |
5161d02c96b7
doc: Add help text for dynamic naming "(var)" of structure fields.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
422 for i = 1:rows (names) |
5161d02c96b7
doc: Add help text for dynamic naming "(var)" of structure fields.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
423 database.(names(i,:)) = ages(i); |
5161d02c96b7
doc: Add help text for dynamic naming "(var)" of structure fields.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
424 endfor |
5161d02c96b7
doc: Add help text for dynamic naming "(var)" of structure fields.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
425 database |
5161d02c96b7
doc: Add help text for dynamic naming "(var)" of structure fields.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
426 @result{} database = |
5161d02c96b7
doc: Add help text for dynamic naming "(var)" of structure fields.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
427 @{ |
5161d02c96b7
doc: Add help text for dynamic naming "(var)" of structure fields.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
428 Bill = 37 |
5161d02c96b7
doc: Add help text for dynamic naming "(var)" of structure fields.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
429 Mary = 26 |
5161d02c96b7
doc: Add help text for dynamic naming "(var)" of structure fields.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
430 John = 31 |
5161d02c96b7
doc: Add help text for dynamic naming "(var)" of structure fields.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
431 @} |
5161d02c96b7
doc: Add help text for dynamic naming "(var)" of structure fields.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
432 @end group |
5161d02c96b7
doc: Add help text for dynamic naming "(var)" of structure fields.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
433 @end example |
5161d02c96b7
doc: Add help text for dynamic naming "(var)" of structure fields.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
434 |
5161d02c96b7
doc: Add help text for dynamic naming "(var)" of structure fields.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
435 The third way to create structures is the @code{struct} command. @code{struct} |
5161d02c96b7
doc: Add help text for dynamic naming "(var)" of structure fields.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
436 takes pairs of arguments, where the first argument in the pair is the fieldname |
5161d02c96b7
doc: Add help text for dynamic naming "(var)" of structure fields.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
437 to include in the structure and the second is a scalar or cell array, |
5161d02c96b7
doc: Add help text for dynamic naming "(var)" of structure fields.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
438 representing the values to include in the structure or structure array. For |
5161d02c96b7
doc: Add help text for dynamic naming "(var)" of structure fields.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
439 example: |
6837 | 440 |
441 @example | |
442 @group | |
7031 | 443 struct ("field1", 1, "field2", 2) |
6837 | 444 @result{} ans = |
445 @{ | |
446 field1 = 1 | |
447 field2 = 2 | |
448 @} | |
449 @end group | |
450 @end example | |
451 | |
452 If the values passed to @code{struct} are a mix of scalar and cell | |
453 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
|
454 structure array with a consistent dimension. For example: |
6837 | 455 |
456 @example | |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9312
diff
changeset
|
457 @group |
9312
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
458 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
|
459 "field3", 3); |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
460 s.field1 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
461 @result{} |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
462 ans = 1 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
463 ans = one |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
464 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
465 s.field2 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
466 @result{} |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
467 ans = 2 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
468 ans = two |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
469 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
470 s.field3 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
471 @result{} |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
472 ans = 3 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
473 ans = 3 |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9312
diff
changeset
|
474 @end group |
6837 | 475 @end example |
476 | |
9312
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
477 If you want to create a struct which contains a cell array as an |
12596
5161d02c96b7
doc: Add help text for dynamic naming "(var)" of structure fields.
Rik <octave@nomad.inbox5.com>
parents:
12575
diff
changeset
|
478 individual field, you must wrap it in another cell array as shown in |
9312
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
479 the following example: |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
480 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
481 @example |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9312
diff
changeset
|
482 @group |
9312
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
483 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
|
484 @result{} ans = |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
485 @{ |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
486 field1 = |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17152
diff
changeset
|
487 |
9312
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
488 @{ |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
489 [1,1] = 1 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
490 [1,2] = one |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
491 @} |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17152
diff
changeset
|
492 |
9312
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
493 field2 = 2 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
494 @} |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9312
diff
changeset
|
495 @end group |
15615
808e4f13e220
doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14856
diff
changeset
|
496 @end example |
9312
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
497 |
6837 | 498 @DOCSTRING(struct) |
499 | |
9312
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
500 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
|
501 structure or a structure array. |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
502 |
6837 | 503 @DOCSTRING(isstruct) |
504 | |
9312
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
505 @node Manipulating Structures |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
506 @subsection Manipulating Structures |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
507 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
508 Other functions that can manipulate the fields of a structure are given below. |
6837 | 509 |
11537
a4b0e292107f
Add undocumented function nfields to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
510 @DOCSTRING(nfields) |
6837 | 511 |
512 @DOCSTRING(fieldnames) | |
513 | |
514 @DOCSTRING(isfield) | |
515 | |
15615
808e4f13e220
doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14856
diff
changeset
|
516 @DOCSTRING(setfield) |
6837 | 517 |
15615
808e4f13e220
doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14856
diff
changeset
|
518 @DOCSTRING(getfield) |
11537
a4b0e292107f
Add undocumented function nfields to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
519 |
a4b0e292107f
Add undocumented function nfields to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
520 @DOCSTRING(rmfield) |
a4b0e292107f
Add undocumented function nfields to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
521 |
a4b0e292107f
Add undocumented function nfields to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
522 @DOCSTRING(orderfields) |
a4b0e292107f
Add undocumented function nfields to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
523 |
6863 | 524 @DOCSTRING(substruct) |
525 | |
526 @node Processing Data in Structures | |
527 @subsection Processing Data in Structures | |
6837 | 528 |
6939 | 529 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
|
530 loop (@pxref{Looping Over Structure Elements}). A similar effect can be |
6863 | 531 achieved with the @code{structfun} function, where a user defined |
17097
e7a059a9a644
doc: Use XREF as anchor prefix in documentation for clearer results in Info viewer.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
532 function is applied to each field of the structure. |
e7a059a9a644
doc: Use XREF as anchor prefix in documentation for clearer results in Info viewer.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
533 @xref{XREFstructfun,,structfun}. |
6863 | 534 |
6939 | 535 Alternatively, to process the data in a structure, the structure might |
6863 | 536 be converted to another type of container before being treated. |
537 | |
538 @DOCSTRING(struct2cell) | |
6837 | 539 |
6517 | 540 @node Cell Arrays |
6837 | 541 @section Cell Arrays |
3439 | 542 @cindex cell arrays |
543 | |
6514 | 544 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
|
545 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
|
546 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
|
547 @math{N}-dimensional arrays with the exception of the use of @samp{@{} |
6514 | 548 and @samp{@}} as allocation and indexing operators. |
549 | |
9312
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
550 @menu |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
551 * Basic Usage of Cell Arrays:: |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
552 * Creating Cell Arrays:: |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
553 * Indexing Cell Arrays:: |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
554 * Cell Arrays of Strings:: |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
555 * Processing Data in Cell Arrays:: |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
556 @end menu |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
557 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
558 @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
|
559 @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
|
560 @opindex @{ |
2090995ca588
Correct en-dash,em-dash instances in docstrings.
Rik <octave@nomad.inbox5.com>
parents:
11537
diff
changeset
|
561 @opindex @} |
6514 | 562 As an example, the following code creates a cell array containing a |
563 string and a 2-by-2 random matrix | |
564 | |
565 @example | |
566 c = @{"a string", rand(2, 2)@}; | |
567 @end example | |
568 | |
569 @noindent | |
9312
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
570 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
|
571 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
|
572 can be indexed like this: |
6514 | 573 |
574 @example | |
575 @group | |
576 c@{1@} | |
577 @result{} ans = a string | |
578 @end group | |
579 @end example | |
580 | |
581 @noindent | |
582 As with numerical arrays several elements of a cell array can be | |
583 extracted by indexing with a vector of indexes | |
584 | |
585 @example | |
586 @group | |
587 c@{1:2@} | |
12944
1acb639204d0
Fix incorrect documentation for cs-lists from cell arrays.
Ben Abbott <bpabbott@mac.com>
parents:
12923
diff
changeset
|
588 @result{} ans = a string |
6514 | 589 @result{} ans = |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17152
diff
changeset
|
590 |
6514 | 591 0.593993 0.627732 |
592 0.377037 0.033643 | |
593 @end group | |
594 @end example | |
595 | |
596 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
|
597 of a cell array. The following code inserts the scalar 3 on the |
6514 | 598 third place of the previously created cell array |
599 | |
600 @example | |
601 @group | |
602 c@{3@} = 3 | |
603 @result{} c = | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17152
diff
changeset
|
604 |
6514 | 605 @{ |
606 [1,1] = a string | |
607 [1,2] = | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17152
diff
changeset
|
608 |
6514 | 609 0.593993 0.627732 |
610 0.377037 0.033643 | |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17152
diff
changeset
|
611 |
6514 | 612 [1,3] = 3 |
613 @} | |
614 @end group | |
615 @end example | |
616 | |
9312
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
617 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
|
618 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
619 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
|
620 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
|
621 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
|
622 function. |
6868 | 623 |
624 @DOCSTRING(celldisp) | |
625 | |
9312
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
626 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
|
627 function. For example: |
9312
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
628 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
629 @example |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
630 @group |
14856
c3fd61c59e9c
maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents:
14733
diff
changeset
|
631 iscell (c) |
9312
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
632 @result{} ans = 1 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
633 |
14856
c3fd61c59e9c
maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents:
14733
diff
changeset
|
634 iscell (3) |
9312
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
635 @result{} ans = 0 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
636 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
637 @end group |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
638 @end example |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
639 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
640 @DOCSTRING(iscell) |
6516 | 641 |
6514 | 642 @node Creating Cell Arrays |
17152
f2a8592b8fbd
doc: Shorten some long subsection names in Manual.
Rik <rik@octave.org>
parents:
17097
diff
changeset
|
643 @subsection Creating Cell Arrays |
6514 | 644 |
9312
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
645 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
|
646 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
|
647 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
|
648 then fill it with data. |
6514 | 649 |
650 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
|
651 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
|
652 function for creating new numerical arrays. The following example creates |
6514 | 653 a 2-by-2 cell array containing empty matrices |
654 | |
655 @example | |
656 @group | |
14856
c3fd61c59e9c
maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents:
14733
diff
changeset
|
657 c = cell (2,2) |
6514 | 658 @result{} c = |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17152
diff
changeset
|
659 |
6514 | 660 @{ |
661 [1,1] = [](0x0) | |
662 [2,1] = [](0x0) | |
663 [1,2] = [](0x0) | |
664 [2,2] = [](0x0) | |
665 @} | |
666 @end group | |
667 @end example | |
668 | |
10828
322f43e0e170
Grammarcheck .txi documentation files.
Rik <octave@nomad.inbox5.com>
parents:
10122
diff
changeset
|
669 Just like numerical arrays, cell arrays can be multi-dimensional. The |
6514 | 670 @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
|
671 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
|
672 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
|
673 following example two cell arrays of equal size are created, and the size |
6514 | 674 of the first one is displayed |
675 | |
676 @example | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9036
diff
changeset
|
677 @group |
14856
c3fd61c59e9c
maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents:
14733
diff
changeset
|
678 c1 = cell (3, 4, 5); |
c3fd61c59e9c
maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents:
14733
diff
changeset
|
679 c2 = cell ( [3, 4, 5] ); |
c3fd61c59e9c
maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents:
14733
diff
changeset
|
680 size (c1) |
6514 | 681 @result{} ans = |
682 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
|
683 @end group |
6514 | 684 @end example |
685 | |
686 @noindent | |
17097
e7a059a9a644
doc: Use XREF as anchor prefix in documentation for clearer results in Info viewer.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
687 As can be seen, the @ref{XREFsize,,size} function also works |
9312
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
688 for cell arrays. As do other functions describing the size of an |
17097
e7a059a9a644
doc: Use XREF as anchor prefix in documentation for clearer results in Info viewer.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
689 object, such as @ref{XREFlength,,length}, @ref{XREFnumel,, numel}, |
e7a059a9a644
doc: Use XREF as anchor prefix in documentation for clearer results in Info viewer.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
690 @ref{XREFrows,,rows}, and @ref{XREFcolumns,,columns}. |
9312
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
691 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
692 @DOCSTRING(cell) |
6514 | 693 |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9036
diff
changeset
|
694 As an alternative to creating empty cell arrays, and then filling them, it |
6514 | 695 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
|
696 @code{num2cell}, @code{mat2cell} and @code{cellslices} functions. |
6514 | 697 |
698 @DOCSTRING(num2cell) | |
699 | |
700 @DOCSTRING(mat2cell) | |
701 | |
10122
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9758
diff
changeset
|
702 @DOCSTRING(cellslices) |
9d1a14e12431
Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9758
diff
changeset
|
703 |
6514 | 704 @node Indexing Cell Arrays |
6837 | 705 @subsection Indexing Cell Arrays |
6514 | 706 |
9312
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
707 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
|
708 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
|
709 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
|
710 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
|
711 following example illustrates the difference: |
6514 | 712 |
713 @example | |
9312
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
714 @group |
14733
baa10bd6f8df
doc: Change cell contents for clarity
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
715 c = @{"1", "2", "3"; "x", "y", "z"; "4", "5", "6"@}; |
9312
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
716 c@{2,3@} |
14733
baa10bd6f8df
doc: Change cell contents for clarity
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
717 @result{} ans = z |
9312
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 c(2,3) |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
720 @result{} ans = |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
721 @{ |
14733
baa10bd6f8df
doc: Change cell contents for clarity
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
722 [1,1] = z |
9312
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
723 @} |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
724 @end group |
6514 | 725 @end example |
726 | |
9312
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
727 @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
|
728 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
|
729 array. |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
730 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
731 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
|
732 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
|
733 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
|
734 with the following command: |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
735 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
736 @example |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
737 @group |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
738 c(:, [1, 3]) = @{0@} |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
739 @result{} = |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
740 @{ |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
741 [1,1] = 0 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
742 [2,1] = 0 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
743 [3,1] = 0 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
744 [1,2] = 2 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
745 [2,2] = 10 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
746 [3,2] = 20 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
747 [1,3] = 0 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
748 [2,3] = 0 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
749 [3,3] = 0 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
750 @} |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
751 @end group |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
752 @end example |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
753 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
754 Note, that the above can also be achieved like this: |
6514 | 755 |
756 @example | |
9312
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
757 c(:, [1, 3]) = 0; |
6514 | 758 @end example |
759 | |
9312
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
760 @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
|
761 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
|
762 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
763 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
|
764 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
|
765 following command: |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
766 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
767 @example |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
768 @group |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
769 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
|
770 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
|
771 @result{} = |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
772 @{ |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
773 [1,1] = 4 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
774 [2,1] = 1 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
775 [1,2] = 5 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
776 [2,2] = 2 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
777 [1,3] = 6 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
778 [2,3] = 3 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
779 @} |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
780 @end group |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
781 @end example |
6514 | 782 |
6518 | 783 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
|
784 @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
|
785 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
|
786 @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
|
787 example can be swapped back like this: |
6837 | 788 |
9312
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
789 @example |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
790 @group |
14856
c3fd61c59e9c
maint: Use Octave coding conventions for cuddling parentheses in doc directory
Rik <octave@nomad.inbox5.com>
parents:
14733
diff
changeset
|
791 [c@{[1,2], :@}] = deal (c@{[2, 1], :@}) |
9312
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
792 @result{} = |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
793 @{ |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
794 [1,1] = 1 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
795 [2,1] = 4 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
796 [1,2] = 2 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
797 [2,2] = 5 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
798 [1,3] = 3 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
799 [2,3] = 6 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
800 @} |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
801 @end group |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
802 @end example |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
803 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
804 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
|
805 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
|
806 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
807 @example |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
808 @group |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
809 x = @{"1", "2"; "3", "4"@}; |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
810 x(1, :) = [] |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
811 @result{} x = |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
812 @{ |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
813 [1,1] = 3 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
814 [1,2] = 4 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
815 @} |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
816 @end group |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
817 @end example |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
818 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
819 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
|
820 array elements but not delete the space for them: |
6837 | 821 |
822 @example | |
823 @group | |
7031 | 824 x = @{"1", "2"; "3", "4"@}; |
6839 | 825 x@{1, :@} = [] |
826 @result{} x = | |
827 @{ | |
6837 | 828 [1,1] = [](0x0) |
829 [2,1] = 3 | |
830 [1,2] = [](0x0) | |
831 [2,2] = 4 | |
6839 | 832 @} |
6837 | 833 @end group |
834 @end example | |
835 | |
12575
d0b799dafede
Grammarcheck files for 3.4.1 release.
Rik <octave@nomad.inbox5.com>
parents:
12535
diff
changeset
|
836 The indexing operations operate on the cell array and not on the objects |
12535
1eb430d9a1b9
Add cellindexmat function to documentation.
Rik <octave@nomad.inbox5.com>
parents:
12175
diff
changeset
|
837 within the cell array. By contrast, @code{cellindexmat} applies matrix indexing |
1eb430d9a1b9
Add cellindexmat function to documentation.
Rik <octave@nomad.inbox5.com>
parents:
12175
diff
changeset
|
838 to the objects within each cell array entry and returns the requested values. |
1eb430d9a1b9
Add cellindexmat function to documentation.
Rik <octave@nomad.inbox5.com>
parents:
12175
diff
changeset
|
839 |
1eb430d9a1b9
Add cellindexmat function to documentation.
Rik <octave@nomad.inbox5.com>
parents:
12175
diff
changeset
|
840 @DOCSTRING(cellindexmat) |
1eb430d9a1b9
Add cellindexmat function to documentation.
Rik <octave@nomad.inbox5.com>
parents:
12175
diff
changeset
|
841 |
6837 | 842 @node Cell Arrays of Strings |
843 @subsection Cell Arrays of Strings | |
844 | |
845 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
|
846 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
|
847 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
|
848 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
|
849 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
|
850 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
|
851 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
|
852 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
|
853 @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
|
854 (@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
|
855 converts a character array to a cell array of strings: |
6837 | 856 |
857 @example | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9036
diff
changeset
|
858 @group |
6837 | 859 a = ["hello"; "world"]; |
860 c = cellstr (a) | |
861 @result{} c = | |
862 @{ | |
863 [1,1] = hello | |
864 [2,1] = world | |
865 @} | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9036
diff
changeset
|
866 @end group |
6837 | 867 @end example |
868 | |
9312
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
869 @DOCSTRING(cellstr) |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
870 |
8828 | 871 One further advantage of using cell arrays to store multiple strings is |
6837 | 872 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
|
873 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
|
874 one string with many others using the @code{strcmp} function. If one of |
6837 | 875 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
|
876 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
|
877 argument: |
6837 | 878 |
879 @example | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9036
diff
changeset
|
880 @group |
6837 | 881 c = @{"hello", "world"@}; |
882 strcmp ("hello", c) | |
883 @result{} ans = | |
884 1 0 | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9036
diff
changeset
|
885 @end group |
6837 | 886 @end example |
887 | |
888 @noindent | |
9312
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
889 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
|
890 @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
|
891 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
|
892 @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
|
893 @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
|
894 @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
|
895 Strings}) and @code{str2double} (@pxref{String Conversions}). |
6837 | 896 |
9312
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
897 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
|
898 cell array of strings. |
6837 | 899 |
900 @DOCSTRING(iscellstr) | |
901 | |
902 @node Processing Data in Cell Arrays | |
903 @subsection Processing Data in Cell Arrays | |
904 | |
905 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
|
906 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
|
907 is to iterate through it using one or more @code{for} loops. The same |
8828 | 908 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
|
909 function that calls a user-specified function on all elements of a cell |
17097
e7a059a9a644
doc: Use XREF as anchor prefix in documentation for clearer results in Info viewer.
Rik <rik@octave.org>
parents:
16816
diff
changeset
|
910 array. @xref{XREFcellfun,,cellfun}. |
6837 | 911 |
912 An alternative is to convert the data to a different container, such as | |
913 a matrix or a data structure. Depending on the data this is possible | |
914 using the @code{cell2mat} and @code{cell2struct} functions. | |
915 | |
916 @DOCSTRING(cell2mat) | |
917 | |
918 @DOCSTRING(cell2struct) | |
919 | |
920 @node Comma Separated Lists | |
921 @section Comma Separated Lists | |
922 @cindex comma separated lists | |
8541
d2cf983bdc9d
container.txi: define cs-list
John W. Eaton <jwe@octave.org>
parents:
8493
diff
changeset
|
923 @cindex cs-lists |
6837 | 924 |
9312
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
925 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
|
926 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
|
927 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
|
928 example |
6837 | 929 |
930 @example | |
931 max (@var{a}, @var{b}) | |
932 @end example | |
933 | |
934 @noindent | |
9312
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
935 @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
|
936 can appear on both the right and left hand side of an assignment. For |
6837 | 937 example |
6514 | 938 |
939 @example | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9036
diff
changeset
|
940 @group |
9312
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
941 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
|
942 [@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
|
943 @end group |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
944 @end example |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
945 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
946 @noindent |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
947 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
|
948 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
|
949 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
|
950 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
|
951 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
952 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
|
953 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
|
954 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
|
955 Arrays}). In the expressions |
9312
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
956 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
957 @example |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9312
diff
changeset
|
958 @group |
9312
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
959 a = [1, 2, 3, 4]; |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
960 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
|
961 @end group |
9312
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
962 @end example |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
963 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
964 @noindent |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
965 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
|
966 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
967 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
|
968 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
|
969 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
|
970 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
|
971 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
|
972 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
973 @menu |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
974 * 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
|
975 * 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
|
976 @end menu |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
977 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
978 @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
|
979 @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
|
980 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
981 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
|
982 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
|
983 @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
|
984 @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
|
985 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
986 @example |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
987 @group |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
988 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
|
989 b = [a@{1:4@}] |
6514 | 990 @result{} b = |
12923
b7e526ce7a3a
Fix incorrect example output for concatenating cs-lists from cells
Jordi Gutiérrez Hermoso <jordigh@gmail.com>
parents:
12596
diff
changeset
|
991 1 2 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
|
992 @end group |
6514 | 993 @end example |
994 | |
9312
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
995 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
|
996 elements selected with @code{@{@}}. By surrounding the list with |
8828 | 997 @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
|
998 following example illustrates: |
6514 | 999 |
1000 @example | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9036
diff
changeset
|
1001 @group |
6514 | 1002 a = @{1, rand(2, 2), "three"@}; |
1003 b = @{ a@{ [1, 3] @} @} | |
1004 @result{} b = | |
1005 @{ | |
1006 [1,1] = 1 | |
1007 [1,2] = three | |
1008 @} | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9036
diff
changeset
|
1009 @end group |
6514 | 1010 @end example |
1011 | |
9312
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
1012 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
|
1013 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
|
1014 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
|
1015 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
|
1016 @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
|
1017 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
|
1018 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
1019 @example |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
1020 @group |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
1021 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
|
1022 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
|
1023 @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
|
1024 printf ("%s ", c@{:@}); |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
1025 @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
|
1026 @end group |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
1027 @end example |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
1028 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
1029 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
|
1030 generated with @code{@{@}} can be assigned to. An example is |
6514 | 1031 |
1032 @example | |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9036
diff
changeset
|
1033 @group |
9312
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
1034 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
|
1035 in@{2@} = inf; |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
1036 in@{3@} = "last"; |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
1037 in@{4@} = "first"; |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
1038 out = cell (4, 1); |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
1039 [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
|
1040 [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
|
1041 @result{} out = |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
1042 @{ |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
1043 [1,1] = 1 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
1044 [2,1] = 9 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
1045 [3,1] = 90 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
1046 [4,1] = 1 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
1047 [3,1] = 1 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
1048 [4,1] = 10 |
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
1049 @} |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
9036
diff
changeset
|
1050 @end group |
6514 | 1051 @end example |
1052 | |
1053 | |
9312
0f7480d07f6a
update documentation of container types in container.txi
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
9209
diff
changeset
|
1054 @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
|
1055 @subsection Comma Separated Lists Generated from Structure Arrays |
6939 | 1056 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
|
1057 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
|
1058 array. For example: |
6514 | 1059 |
6837 | 1060 @example |
1061 @group | |
1062 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
|
1063 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
|
1064 "call2", @{x, inf, "first"@}); |
7031 | 1065 out = struct ("call1", cell (2, 1), "call2", cell (2, 1)); |
6837 | 1066 [out.call1] = find (in.call1); |
1067 [out.call2] = find (in.call2); | |
1068 @end group | |
1069 @end example |