www.gusucode.com > mbctools 工具箱 matlab 源码程序 > mbctools/@sweepsetfilter/setAllows.m
function obj = setAllows(obj, Properties, Values) %SETALLOWS Set flag values % % SSF = SETALLOWS(SSF, PROP, VAL) sets the flags listed in PROP to have % the logical values VAL. % % Examples: % properties = setAllows(ssf) % ssf = setAllows(ssf, 'variables', 'on') % ssf = setAllows(ssf, {'variables', 'filters'}, 'on') % ssf = setAllows(ssf, {'variables', 'filters'}, true) % ssf = setAllows(ssf, {'variables', 'filters'}, {'on', 'off'}) % ssf = setAllows(ssf, {'variables', 'filters'}, [true, false]) % ssf = setAllows(ssf, {'variables', 'filters'}, {true, false}) % ssf = setAllows(ssf, struct( ... % 'variables', 'on', ... % 'filters', 'off')) % % See also SWEEPSETFILTER, SWEEPSETFILTER/GETALLOWS. % Copyright 2000-2012 The MathWorks, Inc. and Ford Global Technologies, Inc. [valid_props, prop_flags] = allowsProperties; % Have we got any properties? ALLPROPS = nargin < 2; if ALLPROPS obj = valid_props'; return end % Ensure that PROPERTIEWS is a cell array if isstruct( Properties ) Values = struct2cell( Properties ); Properties = fieldnames( Properties ); elseif ischar(Properties) Properties = {Properties}; end % Input values can be strings or double arrays or cell arrays of strings if ischar(Values) || (iscell(Values) && ischar(Values{1})) Values = strcmp(Values, 'on'); elseif iscell(Values) Values = [Values{:}]; else Values = Values(:); end % Scalar expansion to size of properties if numel(Values) == 1 Values = repmat(Values, size(Properties)); end % Get flag settings [f, Funcs, Order] = getFlags; % What are the allowed properties before INITIAL_ALLOWS = obj.allowsFlag; for i = 1:length(Properties) property = lower(Properties{i}); mInd = find( strncmp( property,valid_props,length(property) ) ); if isempty(mInd) || length(mInd) > 1 error(message('mbc:sweepsetfilter:InvalidArgument7', property)); end obj.allowsFlag = bitset( obj.allowsFlag, f.(prop_flags{mInd}), Values(i) ); end % May need to update the cache to reflect changes in the flag if ~isequal(INITIAL_ALLOWS, obj.allowsFlag) % Find first flag in Order vector that has a bit change and call that % update function BitChanges = bitxor(INITIAL_ALLOWS, obj.allowsFlag); IsChanged = bitget(BitChanges, Order); StartIdx = find(IsChanged, 1); if ~isempty(StartIdx) obj = Funcs{Order(StartIdx)}(obj); end end