CDATA constant data object class constructor. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: CDATA constant data object class constructor. Create a constant data object. Properties: name - name of data object vals - data values tags - cell array: could be one descriptive tag per value xunits - this is used to label the x-axis on plots. yunits - this is used to label the y-axis on plots. version - version of the constructor code created - creation time of this fsdata object. Possible constructors: c = cdata() - creates a blank data object c = cdata(pl) - creates a data object with the given parameter list which contains 'N' and 'Val' c = cdata(vals) - creates a data object with the given data values. c = cdata(N,v) - creates a data object with N samples all of value, v. HISTORY: 30-01-2007 Hewitson Creation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001 function c = cdata(varargin) 0002 % CDATA constant data object class constructor. 0003 % 0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0005 % 0006 % DESCRIPTION: CDATA constant data object class constructor. 0007 % Create a constant data object. 0008 % 0009 % Properties: 0010 % name - name of data object 0011 % vals - data values 0012 % tags - cell array: could be one descriptive tag per value 0013 % xunits - this is used to label the x-axis on plots. 0014 % yunits - this is used to label the y-axis on plots. 0015 % version - version of the constructor code 0016 % created - creation time of this fsdata object. 0017 % 0018 % Possible constructors: 0019 % c = cdata() - creates a blank data object 0020 % c = cdata(pl) - creates a data object with the given 0021 % parameter list which contains 'N' and 'Val' 0022 % c = cdata(vals) - creates a data object with the given 0023 % data values. 0024 % c = cdata(N,v) - creates a data object with N samples all of 0025 % value, v. 0026 % 0027 % HISTORY: 30-01-2007 Hewitson 0028 % Creation 0029 % 0030 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0031 0032 VERSION = '$Id: cdata.m,v 1.14 2007/10/12 15:30:16 ingo Exp $'; 0033 0034 %%%%%%%%%%%%%%%%%%%%%%%% define cdata properties %%%%%%%%%%%%%%%%%%%%%%%%% 0035 0036 function c = init() 0037 c.name = 'None'; 0038 c.vals = []; 0039 c.tags = {}; 0040 c.xunits = 'N/A'; 0041 c.yunits = 'N/A'; 0042 c.version = VERSION; 0043 c.created = time; 0044 c = class(c, 'cdata'); 0045 end 0046 0047 %%%%%%%%%%%%%%%%%%%%%%%%%% Create cdata object %%%%%%%%%%%%%%%%%%%%%%%%%%% 0048 0049 %%%%%%%%%% val = cdata() %%%%%%%%%% 0050 % create default cdata object 0051 if nargin == 0 0052 c = init(); 0053 0054 elseif nargin == 1 0055 0056 %%%%%%%%%% Create from XML fragment %%%%%%%%%%% 0057 if isa(varargin{1}, 'org.apache.xerces.dom.DeferredElementImpl') 0058 c = fromxml(varargin{1}); 0059 %%%%%%%%%%% From File %%%%%%%%%%%%%%%% 0060 elseif ischar(varargin{1}) 0061 0062 filename = varargin{1}; 0063 [path, name, ext, vers] = fileparts(filename); 0064 switch ext 0065 case '.mat' 0066 c = load(filename); 0067 case '.xml' 0068 c = xmlparse(cdata, filename); 0069 otherwise 0070 error('### Unknown file type.'); 0071 end 0072 %%%%%%%%%% val = cdata(cdata) %%%%%%%%%% 0073 elseif isa(varargin{1}, 'cdata') 0074 c = varargin{1}; 0075 0076 %%%%%%%%%% val = cdata(struct) %%%%%%%%%% 0077 elseif isstruct(varargin{1}) 0078 0079 c = init(); 0080 0081 fields = fieldnames(varargin{1}); 0082 for ii = 1:length(fields) 0083 field = fields{ii}; 0084 0085 %%% created -> time-object 0086 if strcmp(field, 'created') 0087 created = varargin{1}.created; 0088 if isstruct(created) 0089 created = time(created); 0090 end 0091 c.created = created; 0092 %%% All other 0093 else 0094 try 0095 c.(field) = varargin{1}.(field); 0096 catch 0097 error('### The field ''%s'' in the struct is not a cdata property.', field) 0098 end 0099 end 0100 end 0101 0102 %%%%%%%%%% val = cdata(plist) %%%%%%%%%% 0103 elseif isa(varargin{1}, 'plist') 0104 0105 c = init(); 0106 0107 % get possible parameters 0108 fcn = find(varargin{1}, 'fcn'); 0109 vals = find(varargin{1}, 'vals'); 0110 0111 % check which to use 0112 if ~isempty(fcn) 0113 % do function constructor 0114 vals = eval(fcn); 0115 elseif ~isempty(vals) 0116 % do vals constructor 0117 %- nothing to do here. 0118 else 0119 error('### unknown constructor method for cdata.'); 0120 end 0121 0122 c.name = fcn; 0123 c.vals = vals; 0124 0125 %%%%%%%%%% val = cdata(vals) %%%%%%%%%% 0126 else 0127 0128 c = init(); 0129 c.name = 'Data'; 0130 c.vals = varargin{1}; 0131 0132 end 0133 0134 0135 %%%%%%%%%% val = cdata(N,val) %%%%%%%%%% 0136 elseif nargin == 2 0137 0138 %%%%%%%%%%% From DATABASE 0139 if isa(varargin{1}, 'database') 0140 c = retrieve(varargin{1}, varargin{2:end}); 0141 else 0142 c = init(); 0143 c.name = 'Constant'; 0144 c.vals = ones(varargin{1},1)*varargin{2}; 0145 end 0146 else 0147 error('### Unknown number of constructor arguments.'); 0148 end 0149 0150 % check data 0151 % c = checkCdata(c); 0152 end 0153 0154 0155 %-------------------------------------------------------------------------- 0156 % check vector has right dimensions 0157 function c = checkCdata(c) 0158 0159 x = c.vals; 0160 if size(x, 1) < size(x, 2) 0161 x = x.'; 0162 end 0163 0164 c = set(c, 'vals', x); 0165 end 0166