www.gusucode.com > mbctools 工具箱 matlab 源码程序 > mbctools/@sweepsetfilter/setUserdata.m
function obj = setUserdata(obj, type, index, ud) %SETUSERDATA Set the userdata for an item % % SSF = SETUSERDATA(SSF, TYPE, INDEX, UD) sets the user data for the % INDEX-th item of type TYPE to be UD. TYPE determines which type of % filter, variable etc. to change and must be one of 'variable', 'filter', % 'sweepvariable', 'sweepfilter', 'sweepnote' or 'resampling'. INDEX is % the index of the filter, variable, etc. to change. UD is the data to % set. % % If INDEX is not a scalar then UD should be a cell array the same size as % INDEX. If TYPE is 'resampling' then INDEX has no effect. % % See also SWEEPSETFILTER, SWEEPSETFILTER/GETUSERDATA. % Copyright 2000-2005 The MathWorks, Inc. and Ford Global Technologies, Inc. if ~ischar(type) error(message('mbc:sweepsetfilter:InvalidArgument9')); end % If there is more than 1 index ensure that ud is a cell array of the same % length as index if numel(index) > 1 && ~(iscell(ud) && numel(ud) == numel(index)) error(message('mbc:sweepsetfilter:InvalidArgument10')); end validTypes = {'variable', 'filter', 'sweepvariable', 'sweepfilter', ... 'sweepnote', 'resampling'}; typeIndex = find(strcmp(type, validTypes)); if isempty(typeIndex) error(message('mbc:sweepsetfilter:InvalidArgument11', type)); end switch typeIndex case 1 fieldname = 'variables'; case 2 fieldname = 'filters'; case 3 fieldname = 'sweepVariables'; case 4 fieldname = 'sweepFilters'; case 5 fieldname = 'sweepNotes'; case 6 fieldname = 'resampling'; index = 1; end s = obj.(fieldname); if length(index) == 1 s(index).userdata = ud; else [s(index).userdata] = deal(ud{:}); end obj.(fieldname) = s;