www.gusucode.com > mbcdata 工具箱 matlab 源码程序 > mbcdata/@cgoptimstore/optimset.m
function options = optimset(varargin) %OPTIMSET Create/alter optimization OPTIONS structure. % % OPTIONS = OPTIMSET(OPTIMSTORE) creates an optimization options % structure that can be used with Optimization Toolbox functions. with % the named parameters altered with the specified values. Any parameters % specified in the optimization that match (by name) those in the default % options structure are copied into OPTIONS. % % OPTIONS = OPTIMSET(OLDOPTS, OPTIMSTORE) creates a copy of OLDOPTS and % copies matching parameters from the optimization into it. % % OPTIONS = OPTIMSET(OPTIMFUNCTION, OPTIMSTORE) creates an options % structure with all the parameter names and default values relevant to % the optimization function named in OPTIMFUNCTION and then copies % matching parameters from the optimization into it. % % OPTIONS = OPTIMSET(...,'PARAM1',VALUE1,...) sets the additional named % parameters to the specified values. % See also: CGOPTIMSTORE/GETPARAM. % Copyright 2005 The MathWorks, Inc. and Ford Global Technologies, Inc. if isa(varargin{1}, 'cgoptimstore') obj = varargin{1}; varargin(1) = []; options = optimset; elseif isstruct(varargin{1}) options = varargin{1}; obj = varargin{2}; varargin(1:2) = []; else options = optimset(varargin{1}); obj = varargin{2}; varargin(1:2) = []; end % Apply parameters from the object om = getParameters(obj.OptimRunner); opts = get(om); fnames = fieldnames(opts); if length(fnames) == 1 && strcmp(fnames{1}, 'Options') ... && isa(opts.Options, 'xregoptmgr') % Support the old optim manager structure allpars = get(opts.Options); else allpars = opts; end options = optimset(options, allpars); % Apply any remaining named parameters if numel(varargin)>0 if isParamValue(varargin) options = optimset(options, varargin{:}); else error(message('mbc:cgoptimstore:InvalidArgument9')); end end % Check whether a cell array of arguments contains parameters and values function ret = isParamValue(args) % Check there are an even number of args ret = (bitget(numel(args),1)==0); if ret % Check every other arg is a char ret = all(cellfun(@ischar, args(1:2:end))); end