


SET set a cdata property.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DESCRIPTION: SET set a cdata property.
CALL: c = set(c, 'name', 'my_name');
c = set(c, 'y', y);
c = set(c, 'y', [1 2 3]);
c = set(c, 'vals', [1 2 3]);
c = set(c, 'x', x);
c = set(c, 'x', {'a', 'c', 'c'});
c = set(c, 'tags', {'a', 'c', 'c'});
c = set(c, 'xunits', 'sec');
c = set(c, 'yunits', 'V');
c = set(c, 'created', time());
c = set(c, 'version', 'cdata/set.m,v 1.7...');
VERSION: $Id: set.html,v 1.13 2008/03/26 18:02:25 hewitson Exp $
HISTORY: 30-01-07 M Hewitson
Creation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

0001 function c = set(c, varargin) 0002 % SET set a cdata property. 0003 % 0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0005 % 0006 % DESCRIPTION: SET set a cdata property. 0007 % 0008 % CALL: c = set(c, 'name', 'my_name'); 0009 % c = set(c, 'y', y); 0010 % c = set(c, 'y', [1 2 3]); 0011 % c = set(c, 'vals', [1 2 3]); 0012 % c = set(c, 'x', x); 0013 % c = set(c, 'x', {'a', 'c', 'c'}); 0014 % c = set(c, 'tags', {'a', 'c', 'c'}); 0015 % c = set(c, 'xunits', 'sec'); 0016 % c = set(c, 'yunits', 'V'); 0017 % c = set(c, 'created', time()); 0018 % c = set(c, 'version', 'cdata/set.m,v 1.7...'); 0019 % 0020 % VERSION: $Id: set.html,v 1.13 2008/03/26 18:02:25 hewitson Exp $ 0021 % 0022 % HISTORY: 30-01-07 M Hewitson 0023 % Creation 0024 % 0025 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0026 0027 %%% REMARK: This function don't use the generic set-function!!! 0028 0029 VERSION = '$Id: set.html,v 1.13 2008/03/26 18:02:25 hewitson Exp $'; 0030 CATEGORY = 'Helper'; 0031 DEFAULT_PLIST = plist('name', '', ... 0032 'x', [], ... 0033 'y', [], ... 0034 'xunits', '', ... 0035 'yunits', '', ... 0036 'version', '', ... 0037 'created', time); 0038 0039 propArgin = varargin; 0040 cdata_fields = fieldnames(c); 0041 0042 %%% Plausible check: The default parameter list must contain all fieldnames 0043 if length(cdata_fields) ~= nparams(DEFAULT_PLIST) 0044 error('\n### The DEFAULT_PLIST doesn''t contain all field names of the %s-class!', class(c)); 0045 end 0046 0047 %%% Check if this is a special call: default parameter list, cvs-version, category 0048 if ~isempty(varargin{1}) == 1 && ischar(varargin{1}) 0049 in = varargin{1}; 0050 if strcmp(in, 'Params') 0051 c = DEFAULT_PLIST; 0052 return 0053 elseif strcmp(in, 'Version') 0054 c = VERSION; 0055 return 0056 elseif strcmp(in, 'Category') 0057 c = CATEGORY; 0058 return 0059 end 0060 end 0061 0062 if nargin >= 2 && isa(propArgin{1}, 'plist') 0063 pl = propArgin{1}; 0064 propArgin = {}; 0065 for ii = 1:nparams(pl) 0066 %% The 'key' name of a plist/param is always stored with upper case 0067 %% characters. To set a ao property with this key we have to lower the 0068 %% 'key' characters. 0069 propArgin{end+1} = lower(pl.params(ii).key); 0070 propArgin{end+1} = pl.params(ii).val; 0071 end 0072 end 0073 0074 while length(propArgin) >= 2 0075 0076 prop = propArgin{1}; 0077 val = propArgin{2}; 0078 propArgin = propArgin(3:end); 0079 0080 %%% Special case: If propName is equal to 'vals' then set the 'y' property 0081 if strcmp(prop, 'vals') 0082 for jj = 1:numel(c) 0083 c(jj).y = val; 0084 end 0085 0086 %%% Special case: If propName is equal to 'tags' then set the 'x' property 0087 elseif strcmp(prop, 'tags') 0088 for jj = 1:numel(c) 0089 c(jj).x = val; 0090 end 0091 0092 %%% Normal case 0093 elseif ismember(prop, cdata_fields) 0094 for jj = 1:numel(c) 0095 c(jj).(prop) = val; 0096 end 0097 else 0098 error('### ''%s'' is not a valid %s-object property.', prop, class(c)); 0099 end 0100 0101 end 0102 0103 if (nargout == 0) 0104 display(c); 0105 error('\n### No output variable!\n### Please use: %s = set(%s, ''key'', ''value'');', inputname(1), inputname(1)); 0106 end