time | calls | line |
---|
| | 1 | function o = optimget(options,name,default,flag)
|
| | 2 | %OPTIMGET Get OPTIM OPTIONS parameters.
|
| | 3 | % VAL = OPTIMGET(OPTIONS,'NAME') extracts the value of the named parameter
|
| | 4 | % from optimization options structure OPTIONS, returning an empty matrix if
|
| | 5 | % the parameter value is not specified in OPTIONS. It is sufficient to
|
| | 6 | % type only the leading characters that uniquely identify the
|
| | 7 | % parameter. Case is ignored for parameter names. [] is a valid OPTIONS
|
| | 8 | % argument.
|
| | 9 | %
|
| | 10 | % VAL = OPTIMGET(OPTIONS,'NAME',DEFAULT) extracts the named parameter as
|
| | 11 | % above, but returns DEFAULT if the named parameter is not specified (is [])
|
| | 12 | % in OPTIONS. For example
|
| | 13 | %
|
| | 14 | % val = optimget(opts,'TolX',1e-4);
|
| | 15 | %
|
| | 16 | % returns val = 1e-4 if the TolX parameter is not specified in opts.
|
| | 17 | %
|
| | 18 | % See also OPTIMSET.
|
| | 19 |
|
| | 20 | % Copyright 1984-2011 The MathWorks, Inc.
|
| | 21 |
|
| | 22 | % undocumented usage for fast access with no error checking
|
| 208 | 23 | if (nargin == 4) && isequal(flag,'fast')
|
0.02 | 208 | 24 | o = optimgetfast(options,name,default);
|
| 208 | 25 | return
|
| | 26 | end
|
| | 27 |
|
| | 28 | if nargin < 2
|
| | 29 | error(message('MATLAB:optimget:NotEnoughInputs'));
|
| | 30 | end
|
| | 31 | if nargin < 3
|
| | 32 | default = [];
|
| | 33 | end
|
| | 34 |
|
| | 35 | if ~isempty(options) && ~isa(options,'struct')
|
| | 36 | error(message('MATLAB:optimget:Arg1NotStruct'));
|
| | 37 | end
|
| | 38 |
|
| | 39 | if isempty(options)
|
| | 40 | o = default;
|
| | 41 | return;
|
| | 42 | end
|
| | 43 |
|
| | 44 | allfields = {'Display'; 'MaxFunEvals';'MaxIter';'TolFun';'TolX';'FunValCheck';'OutputFcn';'PlotFcns'};
|
| | 45 |
|
| | 46 | % Include specialized options if appropriate
|
| | 47 | if uselargeoptimstruct
|
| | 48 | optimfields = optimoptiongetfields;
|
| | 49 | allfields = [allfields; optimfields];
|
| | 50 | end
|
| | 51 |
|
| | 52 | Names = allfields;
|
| | 53 |
|
| | 54 | name = deblank(name(:)'); % force this to be a row vector
|
| | 55 | j = find(strncmpi(name,Names,length(name)));
|
| | 56 | if isempty(j) % if no matches
|
| | 57 | error(message('MATLAB:optimget:InvalidPropName', name));
|
| | 58 | elseif length(j) > 1 % if more than one match
|
| | 59 | % Check for any exact matches (in case any names are subsets of others)
|
| | 60 | k = find(strcmpi(name,Names));
|
| | 61 | if length(k) == 1
|
| | 62 | j = k;
|
| | 63 | else
|
| | 64 | msg = ['(' Names{j(1),:}];
|
| | 65 | for k = j(2:length(j))'
|
| | 66 | msg = [msg ', ' Names{k,:}];
|
| | 67 | end
|
| | 68 | msg = [msg, '.)'];
|
| | 69 | error(message('MATLAB:optimget:AmbiguousPropName', name, msg));
|
| | 70 | end
|
| | 71 | end
|
| | 72 |
|
| | 73 | if any(strcmp(Names,Names{j,:}))
|
| | 74 | o = options.(Names{j,:});
|
| | 75 | if isempty(o)
|
| | 76 | o = default;
|
| | 77 | end
|
| | 78 | else
|
| | 79 | o = default;
|
| | 80 | end
|
Other subfunctions in this file are not included in this listing.