1 ## Copyright (C) 2009 VZLU Prague, a.s., Czech Republic
3 ## This program is free software; you can redistribute it and/or modify it under
4 ## the terms of the GNU General Public License as published by the Free Software
5 ## Foundation; either version 3 of the License, or (at your option) any later
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 ## You should have received a copy of the GNU General Public License along with
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
17 ## @deftypefn{Function File} {} get (d, key, defv)
18 ## Queries for the values of specified key(s). Unlike indexing, however,
19 ## this does not throw an error if a key is missing but rather substitutes
20 ## a default value. If @var{key} is a cell array, @var{defv} should be either
21 ## a cell array of the same shape as @var{key}, or a singleton cell.
22 ## Non-cell values will be converted to a singleton cell.
25 ## Author: Jaroslav Hajek <highegg@gmail.com>
27 function val = get (d, key, defv = [])
28 if (nargin < 2 || nargin > 3)
33 i = lookup (d.keys, key, "m");
39 elseif (iscellstr (key))
41 val = repmat ({defv}, size (key));
42 elseif (numel (defv) == 1)
43 val = repmat (defv, size (key));
44 elseif (size_equal (key, defv))
47 error ("get: sizes of key & defv must match");
49 i = lookup (d.keys, key, "m");
51 val(mask) = d.values(i(mask));
53 error ("get: invalid key value");