www.gusucode.com > mbcexpr 工具箱 matlab 源码程序 > mbcexpr/@cglookuptwo/set.m
function varargout = set(varargin) %SET % Copyright 2000-2013 The MathWorks, Inc. and Ford Global Technologies, Inc. % Set method for cglookuptwo Objects % % set(T) displays possible properties to set. % % T = set(T,'values',M); will set the values array to the matrix M. % If the locks field is empty, them M can be any size, if the locks field is % not empty then the size of M must be the same size as the existing field. % % T = set(T,'values',{M,Information}) % sets the values field as above, and passes the argument 'Information' % into the memory field % % T = set(T,'element',[i,j,x]) sets the (i,j) entry in the values matrix to x % provided that this is valid and theat element is not locked. % % T = set(T,'element',{[i,j,x],Information}) as above, and fills up memory field. % % T = set(T,'clips',[l,u]) sets the clips vector to be [l,u]. % % T = set(T,'locks',L) sets the locks field to the matrix L. L should consist % of only 0's and 1's and must be the same size as the values field. % % T = set(T,'locks',[]) sets the locks field to the empty matrix thus allowing % for resizing of the values field % % T = set(T,'matrix',V) sets the values field to the matrix V. Ignores any locks, % thus the table can be resized. if nargin == 1 varargout{1} = i_ShowFields; else LT = varargin{1}; if nargin < 3 error(message('mbc:cglookuptwo:TooFewInputs')); end for i = 2:2:nargin property = varargin{i}; new_value = varargin{i+1}; if ~isa(property , 'char') error(message('mbc:cglookuptwo:InvalidPropertyName')); end switch lower(property) case 'values' LT = i_setvalues(LT,new_value); case 'element' LT = i_element(LT,new_value); case 'clips' % Changes the clipping values. Requires a 1 by 2 vector. If there is % upper or lower clip use Inf or -Inf accordingly. if any(size(new_value)~=[1 2]) error(message('mbc:cglookuptwo:InvalidSize')); else LT.Clips = new_value; end case {'locks','vlocks'} LT = i_locks(LT,new_value); case 'weights' if length(new_value) == length(LT.SFlist) LT.Weights = new_value; else error(message('mbc:cglookuptwo:InvalidSize1')); end case 'matrix' if ~isnumeric(new_value); M = new_value{1}; info = new_value{2}; else M = new_value; info = 'No information'; end LT = set(LT,'locks',[]); LT = setVunofficial(LT,[]); LT = set(LT,'values',{M,info}); if ~isempty(M) LT = set(LT,'locks',zeros(size(M))); LT = clearExtrapolationMask(LT); end case 'description' LT.Description = new_value; case 'input' LT.Input = new_value; case 'precision' LT.Precision = new_value; LT = i_setvalues(LT,{LT.Values,'Resolved to new precision'}); case 'range' if any(size(new_value)~=[1 2]) || diff(new_value)<=0 error(message('mbc:cglookuptwo:InvalidSize')); end LT.Precision= set(LT.Precision,'PhysRange',new_value); LT = i_setvalues(LT,{LT.Values,'Clipped'}); case 'memory' LT.Memory = new_value; otherwise warning(message('mbc:cglookuptwo:InvalidArgument5', property)); end end if nargout > 0 varargout{1} = LT; elseif ~isempty(inputname(1)) assignin('caller' , inputname(1) , LT); end end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % i_ShowFields % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function out = i_ShowFields out.Values = 'm by n Array'; out.element = 'number'; out.Clips = '1 by 2 double'; out.locks = 'm by n array OR empty'; %%%%%%%%%%%%%%%%%%%%%%%%%%%% % i_setvalues % %%%%%%%%%%%%%%%%%%%%%%%%%%%% function LT = i_setvalues(LT,newvalue) if ~isnumeric(newvalue) M = newvalue{1}; info = newvalue{2}; else M = newvalue; info = 'no information'; end if isempty(M) LT.VLocks = []; LT.Values = []; LT = clearExtrapolationMask(LT); else values = LT.Values; vlocks = LT.VLocks; if isempty(values) values = zeros(size(M)); end if ~isempty(vlocks); if ~isequal(size(vlocks),size(M)) error(message('mbc:cglookuptwo:InvalidSize3')); end vlocks = logical(vlocks); M(vlocks) = values(vlocks); end prec = get(LT,'precision'); LT.Values = resolve(prec,M); end LT.Memory(end+1) = cgTableHistory(LT,info); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % i_element % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function out = i_element(LT,newvalue) if ~isnumeric(newvalue); i = newvalue{1}(1); j = newvalue{1}(2); x = newvalue{1}(3); info = newvalue{2}; else i = newvalue(1); j = newvalue(2); x = newvalue(3); info = 'no information'; end val = get(LT,'values'); val(i,j) = x; out = set(LT,'values',{val,info}); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % i_locks % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function LT = i_locks(LT,L) M = get(LT,'values'); if isempty(L) LT.VLocks = []; elseif ~isequal(size(M),size(L)) error(message('mbc:cglookuptwo:InvalidSize4')); elseif ~isequal(L, L.^2) error(message('mbc:cglookuptwo:InvalidPropertyValue')); else LT.VLocks = L; end