www.gusucode.com > mbcmodels 工具箱 matlab 源码程序 > mbcmodels/@xregoptmgr/set.m
function varargout= set(OM,Property,Value,AllProperties,doRecurse) %SET Set a new value for an optimization option. % % OM = set(OM, PROP, VALUE) sets a new value for an optimization manager % option. % Copyright 2000-2011 The MathWorks, Inc. and Ford Global Technologies, Inc. if (nargout==0) && (nargin==1) % display options on command line iOptionString(OM) return end if nargin<4 AllProperties = true; end if nargin<5 doRecurse = true; end dotPosition = find( Property=='.', 1, 'first' ); if ~isempty(dotPosition); % uses the dot notation mainPropName = Property(1:dotPosition-1); subPropName = Property(dotPosition+1:end); mainProp = get( OM, mainPropName , AllProperties); mainProp = set( mainProp, subPropName, Value,AllProperties); OM = set(OM, mainPropName, mainProp); else % main set [OM,nFound]= iMainSet(OM,Property,Value,AllProperties,doRecurse); if nargout<2 % Throw error if we have not found exactly one match and called normally (0 or 1 output) if nFound==0 error(message('mbc:xregoptmgr:InvalidPropertyName', Property)); elseif nFound>1 error(message('mbc:xregoptmgr:InvalidPropertyName3', Property)); end else % return number found (called from iMainSet) varargout{2} = nFound; end end if nargout>0 || isempty(inputname(1)) varargout{1} = OM; else assignin('caller',inputname(1),OM); end %-------------------------------------------------------------------------- function [OM,nFound]= iMainSet(OM,Property,Value,AllProperties,doRecurse) % Find parameter in this OM pind = pGetPropertyIndex(OM, Property, AllProperties); nFound = length(pind); if nFound==0 && doRecurse && ~isempty(OM.foptions) % Now check sub-managers [options, subOM] = suboptimMgrs(OM); nFound = 0; for n = 1:length(options); [subOM{n},nsub] = set( subOM{n}, Property, Value); if nsub == 1 OM = set(OM, options{n}, subOM{n}); end nFound = nFound + nsub; end elseif nFound==1 % Set property in this OM [~,Value] = checkinput(OM,pind,Value); % assign new value OM.foptions(pind).Value = Value; end %-------------------------------------------------------------------------- function iOptionString(OM) optstr = cell(length(OM.foptions),1); for i= 1:length(OM.foptions) optstr{i}= OM.foptions(i).Param; cstr= OM.foptions(i).CheckInput; if ~isempty(cstr) if ischar(cstr) optstr{i}= [optstr{i} sprintf(' [ %s ]',cstr)]; else % cell option check {type,[LB UB]} optstr{i}= [optstr{i} sprintf(' [ %s [%g,%g] ]',cstr{:})]; end end end disp(char(optstr))