annotate scripts/miscellaneous/namedargs2cell.m @ 27919:1891570abac8

update Octave Project Developers copyright for the new year In files that have the "Octave Project Developers" copyright notice, update for 2020.
author John W. Eaton <jwe@octave.org>
date Mon, 06 Jan 2020 22:29:51 -0500
parents b442ec6dda5c
children bd51beb6205e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27919
1891570abac8 update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 27918
diff changeset
1 ## Copyright (C) 2019-2020 The Octave Project Developers
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 27797
diff changeset
2 ##
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 27797
diff changeset
3 ## See the file COPYRIGHT.md in the top-level directory of this distribution
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 27797
diff changeset
4 ## or <https://octave.org/COPYRIGHT.html/>.
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 27797
diff changeset
5 ##
27426
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
6 ##
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
7 ## This file is part of Octave.
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
8 ##
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
9 ## Octave is free software: you can redistribute it and/or modify it
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
10 ## under the terms of the GNU General Public License as published by
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
11 ## the Free Software Foundation, either version 3 of the License, or
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
12 ## (at your option) any later version.
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
13 ##
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
14 ## Octave is distributed in the hope that it will be useful, but
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
15 ## WITHOUT ANY WARRANTY; without even the implied warranty of
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
16 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
17 ## GNU General Public License for more details.
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
18 ##
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
19 ## You should have received a copy of the GNU General Public License
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
20 ## along with Octave; see the file COPYING. If not, see
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
21 ## <https://www.gnu.org/licenses/>.
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
22
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
23 ## -*- texinfo -*-
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
24 ## @deftypefn {} {@var{c} =} namedargs2cell (@var{s})
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
25 ## Create a cell array of field name/value pairs from a scalar structure.
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
26 ##
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
27 ## Example:
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
28 ##
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
29 ## @example
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
30 ## @group
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
31 ## @c doctest: +SKIP
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
32 ## s.Name = "Peter";
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
33 ## s.Height = 185;
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
34 ## s.Age = 42;
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
35 ##
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
36 ## c = namedargs2cell (s)
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
37 ## @result{} @{ "Name", "Peter", "Height", 185, "Age", 42 @}
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
38 ## @end group
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
39 ## @end example
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
40 ##
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
41 ## @seealso{struct2cell}
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
42 ## @end deftypefn
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
43
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
44 function c = namedargs2cell (s)
27797
5dcdd5bd46e2 maint: remove trailing spaces from code.
Rik <rik@octave.org>
parents: 27426
diff changeset
45
27426
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
46 if (nargin != 1 || nargout > 1)
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
47 print_usage ();
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
48 endif
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
49 if (! isstruct (s) || ! isscalar (s))
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
50 error ("namedargs2cell: S must be a scalar structure");
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
51 endif
27797
5dcdd5bd46e2 maint: remove trailing spaces from code.
Rik <rik@octave.org>
parents: 27426
diff changeset
52
27426
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
53 c = reshape ([fieldnames(s), struct2cell(s)].', 1, []);
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
54
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
55 endfunction
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
56
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
57
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
58 %!test
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
59 %! data = { "Name", "Peter", "Height", 185, "Age", 42};
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
60 %! s = struct (data{:});
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
61 %! c = namedargs2cell (s);
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
62 %! assert (isequal (c, data));
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
63
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
64 ## Test input validation
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
65 %!error <Invalid call> namedargs2cell ()
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
66 %!error <Invalid call> namedargs2cell (1, 2)
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
67 %!error <S must be a scalar structure> namedargs2cell (true)
3ec072ab1bda namedargs2cell.m: New function (bug #56903).
Rik <rik@octave.org>
parents:
diff changeset
68 %!error <S must be a scalar structure> namedargs2cell (struct ("name", {1, 2}))