annotate scripts/miscellaneous/setfield.m @ 32632:2e484f9f1f18 stable

maint: update Octave Project Developers copyright for the new year
author John W. Eaton <jwe@octave.org>
date Fri, 22 Dec 2023 12:08:17 -0500
parents 597f3ee61a48
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ########################################################################
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 ##
32632
2e484f9f1f18 maint: update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 31706
diff changeset
3 ## Copyright (C) 2000-2024 The Octave Project Developers
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
4 ##
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 ## See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 ## distribution or <https://octave.org/copyright/>.
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
7 ##
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
8 ## This file is part of Octave.
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
9 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24441
diff changeset
10 ## Octave is free software: you can redistribute it and/or modify it
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
11 ## under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24441
diff changeset
12 ## the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
13 ## (at your option) any later version.
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
14 ##
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
15 ## Octave is distributed in the hope that it will be useful, but
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
18 ## GNU General Public License for more details.
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
19 ##
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
20 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6547
diff changeset
21 ## along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24441
diff changeset
22 ## <https://www.gnu.org/licenses/>.
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 ##
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ########################################################################
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
25
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
26 ## -*- texinfo -*-
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 19852
diff changeset
27 ## @deftypefn {} {@var{sout} =} setfield (@var{s}, @var{field}, @var{val})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 19852
diff changeset
28 ## @deftypefnx {} {@var{sout} =} setfield (@var{s}, @var{sidx1}, @var{field1}, @var{fidx1}, @var{sidx2}, @var{field2}, @var{fidx2}, @dots{}, @var{val})
15615
808e4f13e220 doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
29 ##
19276
1fa328da03ef Overhaul getfield, setfield, orderfields m-files.
Rik <rik@octave.org>
parents: 18533
diff changeset
30 ## Return a @emph{copy} of the structure @var{s} with the field member
19596
0e1f5a750d00 maint: Periodic merge of gui-release to default.
John W. Eaton <jwe@octave.org>
parents: 19276 19593
diff changeset
31 ## @var{field} set to the value @var{val}.
19276
1fa328da03ef Overhaul getfield, setfield, orderfields m-files.
Rik <rik@octave.org>
parents: 18533
diff changeset
32 ##
16816
12005245b645 doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents: 16772
diff changeset
33 ## For example:
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
34 ##
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
35 ## @example
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
36 ## @group
15615
808e4f13e220 doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
37 ## @var{s} = struct ();
808e4f13e220 doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
38 ## @var{s} = setfield (@var{s}, "foo bar", 42);
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
39 ## @end group
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
40 ## @end example
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
41 ##
15615
808e4f13e220 doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
42 ## @noindent
808e4f13e220 doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
43 ## This is equivalent to
808e4f13e220 doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
44 ##
808e4f13e220 doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
45 ## @example
808e4f13e220 doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
46 ## @var{s}.("foo bar") = 42;
808e4f13e220 doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
47 ## @end example
808e4f13e220 doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
48 ##
808e4f13e220 doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
49 ## @noindent
808e4f13e220 doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
50 ## Note that ordinary structure syntax @code{@var{s}.foo bar = 42} cannot be
19276
1fa328da03ef Overhaul getfield, setfield, orderfields m-files.
Rik <rik@octave.org>
parents: 18533
diff changeset
51 ## used here, as the field name is not a valid Octave identifier because of
1fa328da03ef Overhaul getfield, setfield, orderfields m-files.
Rik <rik@octave.org>
parents: 18533
diff changeset
52 ## the space character. Using arbitrary strings for field names is
1fa328da03ef Overhaul getfield, setfield, orderfields m-files.
Rik <rik@octave.org>
parents: 18533
diff changeset
53 ## incompatible with @sc{matlab}, and this usage will emit a warning if the
19852
e9a0bd0b125c Rename 'matlab-incompatible' warning to 'language-extension'.
Carnë Draug <carandraug@octave.org>
parents: 19833
diff changeset
54 ## warning ID @code{Octave:language-extension} is enabled.
28959
5394d688d456 doc: Use @code{} within alternate text for @xref,@pxref macros for better Info display.
Rik <rik@octave.org>
parents: 28896
diff changeset
55 ## @xref{XREFwarning_ids,,@code{warning_ids}}.
15615
808e4f13e220 doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
56 ##
19276
1fa328da03ef Overhaul getfield, setfield, orderfields m-files.
Rik <rik@octave.org>
parents: 18533
diff changeset
57 ## With the second calling form, set a field of a structure array. The
1fa328da03ef Overhaul getfield, setfield, orderfields m-files.
Rik <rik@octave.org>
parents: 18533
diff changeset
58 ## input @var{sidx} selects an element of the structure array, @var{field}
1fa328da03ef Overhaul getfield, setfield, orderfields m-files.
Rik <rik@octave.org>
parents: 18533
diff changeset
59 ## specifies the field name of the selected element, and @var{fidx} selects
1fa328da03ef Overhaul getfield, setfield, orderfields m-files.
Rik <rik@octave.org>
parents: 18533
diff changeset
60 ## which element of the field (in the case of an array or cell array).
1fa328da03ef Overhaul getfield, setfield, orderfields m-files.
Rik <rik@octave.org>
parents: 18533
diff changeset
61 ## The @var{sidx}, @var{field}, and @var{fidx} inputs can be repeated to
1fa328da03ef Overhaul getfield, setfield, orderfields m-files.
Rik <rik@octave.org>
parents: 18533
diff changeset
62 ## address nested structure array elements. The structure array index and
1fa328da03ef Overhaul getfield, setfield, orderfields m-files.
Rik <rik@octave.org>
parents: 18533
diff changeset
63 ## field element index must be cell arrays while the field name must be a
1fa328da03ef Overhaul getfield, setfield, orderfields m-files.
Rik <rik@octave.org>
parents: 18533
diff changeset
64 ## string.
15615
808e4f13e220 doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
65 ##
19276
1fa328da03ef Overhaul getfield, setfield, orderfields m-files.
Rik <rik@octave.org>
parents: 18533
diff changeset
66 ## For example:
15615
808e4f13e220 doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
67 ##
808e4f13e220 doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
68 ## @example
808e4f13e220 doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
69 ## @group
808e4f13e220 doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
70 ## @var{s} = struct ("baz", 42);
19276
1fa328da03ef Overhaul getfield, setfield, orderfields m-files.
Rik <rik@octave.org>
parents: 18533
diff changeset
71 ## setfield (@var{s}, @{1@}, "foo", @{1@}, "bar", 54)
1fa328da03ef Overhaul getfield, setfield, orderfields m-files.
Rik <rik@octave.org>
parents: 18533
diff changeset
72 ## @result{}
1fa328da03ef Overhaul getfield, setfield, orderfields m-files.
Rik <rik@octave.org>
parents: 18533
diff changeset
73 ## ans =
15615
808e4f13e220 doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
74 ## scalar structure containing the fields:
808e4f13e220 doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
75 ## baz = 42
808e4f13e220 doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
76 ## foo =
808e4f13e220 doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
77 ## scalar structure containing the fields:
808e4f13e220 doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
78 ## bar = 54
808e4f13e220 doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
79 ## @end group
808e4f13e220 doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
80 ## @end example
808e4f13e220 doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
81 ##
19597
db92e7e28e1f strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19596
diff changeset
82 ## The example begins with an ordinary scalar structure to which a nested
19276
1fa328da03ef Overhaul getfield, setfield, orderfields m-files.
Rik <rik@octave.org>
parents: 18533
diff changeset
83 ## scalar structure is added. In all cases, if the structure index @var{sidx}
1fa328da03ef Overhaul getfield, setfield, orderfields m-files.
Rik <rik@octave.org>
parents: 18533
diff changeset
84 ## is not specified it defaults to 1 (scalar structure). Thus, the example
1fa328da03ef Overhaul getfield, setfield, orderfields m-files.
Rik <rik@octave.org>
parents: 18533
diff changeset
85 ## above could be written more concisely as
1fa328da03ef Overhaul getfield, setfield, orderfields m-files.
Rik <rik@octave.org>
parents: 18533
diff changeset
86 ## @code{setfield (@var{s}, "foo", "bar", 54)}
15615
808e4f13e220 doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
87 ##
19276
1fa328da03ef Overhaul getfield, setfield, orderfields m-files.
Rik <rik@octave.org>
parents: 18533
diff changeset
88 ## Finally, an example with nested structure arrays:
15615
808e4f13e220 doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
89 ##
808e4f13e220 doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
90 ## @example
808e4f13e220 doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
91 ## @group
808e4f13e220 doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
92 ## @var{sa}.foo = 1;
19276
1fa328da03ef Overhaul getfield, setfield, orderfields m-files.
Rik <rik@octave.org>
parents: 18533
diff changeset
93 ## @var{sa} = setfield (@var{sa}, @{2@}, "bar", @{3@}, "baz", @{1, 4@}, 5);
15615
808e4f13e220 doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
94 ## @var{sa}(2).bar(3)
19276
1fa328da03ef Overhaul getfield, setfield, orderfields m-files.
Rik <rik@octave.org>
parents: 18533
diff changeset
95 ## @result{}
1fa328da03ef Overhaul getfield, setfield, orderfields m-files.
Rik <rik@octave.org>
parents: 18533
diff changeset
96 ## ans =
1fa328da03ef Overhaul getfield, setfield, orderfields m-files.
Rik <rik@octave.org>
parents: 18533
diff changeset
97 ## scalar structure containing the fields:
1fa328da03ef Overhaul getfield, setfield, orderfields m-files.
Rik <rik@octave.org>
parents: 18533
diff changeset
98 ## baz = 0 0 0 5
15615
808e4f13e220 doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
99 ## @end group
808e4f13e220 doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
100 ## @end example
808e4f13e220 doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
101 ##
19276
1fa328da03ef Overhaul getfield, setfield, orderfields m-files.
Rik <rik@octave.org>
parents: 18533
diff changeset
102 ## Here @var{sa} is a structure array whose field at elements 1 and 2 is in
1fa328da03ef Overhaul getfield, setfield, orderfields m-files.
Rik <rik@octave.org>
parents: 18533
diff changeset
103 ## turn another structure array whose third element is a simple scalar
1fa328da03ef Overhaul getfield, setfield, orderfields m-files.
Rik <rik@octave.org>
parents: 18533
diff changeset
104 ## structure. The terminal scalar structure has a field which contains a
1fa328da03ef Overhaul getfield, setfield, orderfields m-files.
Rik <rik@octave.org>
parents: 18533
diff changeset
105 ## matrix value.
15615
808e4f13e220 doc: Update struct documentation to match new indexing rules
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 14363
diff changeset
106 ##
10122
9d1a14e12431 Update docs and add tests for container functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 9849
diff changeset
107 ## Note that the same result as in the above example could be achieved by:
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
108 ##
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
109 ## @example
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
110 ## @group
19276
1fa328da03ef Overhaul getfield, setfield, orderfields m-files.
Rik <rik@octave.org>
parents: 18533
diff changeset
111 ## @var{sa}.foo = 1;
1fa328da03ef Overhaul getfield, setfield, orderfields m-files.
Rik <rik@octave.org>
parents: 18533
diff changeset
112 ## @var{sa}(2).bar(3).baz(1,4) = 5
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
113 ## @end group
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
114 ## @end example
30329
81d26e8481a6 maint: Shorten @seealso lines to less than 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 29359
diff changeset
115 ## @seealso{getfield, rmfield, orderfields, isfield, fieldnames, isstruct,
81d26e8481a6 maint: Shorten @seealso lines to less than 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 29359
diff changeset
116 ## struct}
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
117 ## @end deftypefn
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
118
19276
1fa328da03ef Overhaul getfield, setfield, orderfields m-files.
Rik <rik@octave.org>
parents: 18533
diff changeset
119 function sout = setfield (s, varargin)
1fa328da03ef Overhaul getfield, setfield, orderfields m-files.
Rik <rik@octave.org>
parents: 18533
diff changeset
120
9849
87fd803c583b rewrite getfield and setfield
Jaroslav Hajek <highegg@gmail.com>
parents: 9051
diff changeset
121 if (nargin < 3)
87fd803c583b rewrite getfield and setfield
Jaroslav Hajek <highegg@gmail.com>
parents: 9051
diff changeset
122 print_usage ();
87fd803c583b rewrite getfield and setfield
Jaroslav Hajek <highegg@gmail.com>
parents: 9051
diff changeset
123 endif
19276
1fa328da03ef Overhaul getfield, setfield, orderfields m-files.
Rik <rik@octave.org>
parents: 18533
diff changeset
124
9849
87fd803c583b rewrite getfield and setfield
Jaroslav Hajek <highegg@gmail.com>
parents: 9051
diff changeset
125 subs = varargin(1:end-1);
19276
1fa328da03ef Overhaul getfield, setfield, orderfields m-files.
Rik <rik@octave.org>
parents: 18533
diff changeset
126 val = varargin{end};
12931
cefd568ea073 Replace function handles with function names in cellfun calls for 15% speedup.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
127 flds = cellfun ("isclass", subs, "char");
cefd568ea073 Replace function handles with function names in cellfun calls for 15% speedup.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
128 idxs = cellfun ("isclass", subs, "cell");
19276
1fa328da03ef Overhaul getfield, setfield, orderfields m-files.
Rik <rik@octave.org>
parents: 18533
diff changeset
129 if (! all (flds | idxs))
9849
87fd803c583b rewrite getfield and setfield
Jaroslav Hajek <highegg@gmail.com>
parents: 9051
diff changeset
130 error ("setfield: invalid index");
87fd803c583b rewrite getfield and setfield
Jaroslav Hajek <highegg@gmail.com>
parents: 9051
diff changeset
131 endif
19276
1fa328da03ef Overhaul getfield, setfield, orderfields m-files.
Rik <rik@octave.org>
parents: 18533
diff changeset
132
1fa328da03ef Overhaul getfield, setfield, orderfields m-files.
Rik <rik@octave.org>
parents: 18533
diff changeset
133 typs = ifelse (flds, {"."}, {"()"});
1fa328da03ef Overhaul getfield, setfield, orderfields m-files.
Rik <rik@octave.org>
parents: 18533
diff changeset
134 sout = subsasgn (s, struct ("type", typs, "subs", subs), val);
1fa328da03ef Overhaul getfield, setfield, orderfields m-files.
Rik <rik@octave.org>
parents: 18533
diff changeset
135
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
136 endfunction
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
137
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
138
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
139 %!test
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
140 %! x.a = "hello";
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
141 %! x = setfield (x, "b", "world");
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
142 %! y = struct ("a", "hello", "b", "world");
19276
1fa328da03ef Overhaul getfield, setfield, orderfields m-files.
Rik <rik@octave.org>
parents: 18533
diff changeset
143 %! assert (x, y);
5820
27c966e4b2dc [project @ 2006-05-17 21:00:54 by jwe]
jwe
parents:
diff changeset
144 %!test
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
145 %! oo(1,1).f0 = 1;
19276
1fa328da03ef Overhaul getfield, setfield, orderfields m-files.
Rik <rik@octave.org>
parents: 18533
diff changeset
146 %! oo = setfield (oo,{1,2},"fd",{3},"b", {1,4}, 6);
1fa328da03ef Overhaul getfield, setfield, orderfields m-files.
Rik <rik@octave.org>
parents: 18533
diff changeset
147 %! assert (oo(1,2).fd(3).b(1,4), 6);
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
148
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
149 ## Test input validation
28896
90fea9cc9caa test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents: 27978
diff changeset
150 %!error <Invalid call> setfield ()
90fea9cc9caa test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents: 27978
diff changeset
151 %!error <Invalid call> setfield (1)
90fea9cc9caa test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents: 27978
diff changeset
152 %!error <Invalid call> setfield (1,2)
19276
1fa328da03ef Overhaul getfield, setfield, orderfields m-files.
Rik <rik@octave.org>
parents: 18533
diff changeset
153 %!error <invalid index> setfield (1,2,3)