]> Creatis software - CreaPhase.git/blob - octave_packages/m/optimization/optimget.m
update packages
[CreaPhase.git] / octave_packages / m / optimization / optimget.m
1 ## Copyright (C) 2008-2012 Jaroslav Hajek
2 ## Copyright (C) 2009 VZLU Prague
3 ##
4 ## This file is part of Octave.
5 ##
6 ## Octave is free software; you can redistribute it and/or modify it
7 ## under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation; either version 3 of the License, or (at
9 ## your option) any later version.
10 ##
11 ## Octave is distributed in the hope that it will be useful, but
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 ## General Public License for more details.
15 ##
16 ## You should have received a copy of the GNU General Public License
17 ## along with Octave; see the file COPYING.  If not, see
18 ## <http://www.gnu.org/licenses/>.
19
20 ## -*- texinfo -*-
21 ## @deftypefn  {Function File} {} optimget (@var{options}, @var{parname})
22 ## @deftypefnx {Function File} {} optimget (@var{options}, @var{parname}, @var{default})
23 ## Return a specific option from a structure created by
24 ## @code{optimset}.  If @var{parname} is not a field of the @var{options}
25 ## structure, return @var{default} if supplied, otherwise return an
26 ## empty matrix.
27 ## @end deftypefn
28
29 function retval = optimget (options, parname, default)
30
31   if (nargin < 2 || nargin > 4 || ! isstruct (options) || ! ischar (parname))
32     print_usage ();
33   endif
34
35   opts = __all_opts__ ();
36   idx = lookup (tolower (opts), tolower (parname), "m");
37
38   if (idx)
39     parname = opts{idx};
40   else
41     warning ("unrecognized option: %s", parname);
42   endif
43   if (isfield (options, parname))
44     retval = options.(parname);
45   elseif (nargin > 2)
46     retval = default;
47   else
48     retval = [];
49   endif
50
51 endfunction
52