


CDATA constant data object class constructor.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DESCRIPTION: CDATA constant data object class constructor.
Create a constant data object.
Properties:
name - name of data object
y - data values
x - 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 % y - data values 0012 % x - 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.html,v 1.13 2008/03/26 18:02:25 hewitson Exp $'; 0033 CATEGORY = 'Constructor'; 0034 0035 %%%%% Is this a 'Params' call? %%%%% 0036 if nargin == 2 && isa(varargin{1}, 'cdata') && ischar(varargin{2}) 0037 if strcmp(varargin{2}, 'Params') 0038 c = plist(); 0039 return 0040 elseif strcmp(varargin{2}, 'Version') 0041 c = VERSION; 0042 return 0043 elseif strcmp(varargin{2}, 'Category') 0044 c = CATEGORY; 0045 return 0046 end 0047 end 0048 0049 %%%%%%%%%%%%%%%%%%%%%%%% define cdata properties %%%%%%%%%%%%%%%%%%%%%%%%% 0050 0051 function c = init(version) 0052 c.name = 'None'; 0053 c.y = []; 0054 c.x = {}; 0055 c.xunits = 'N/A'; 0056 c.yunits = 'N/A'; 0057 c.version = version; 0058 c.created = time; 0059 c = class(c, 'cdata'); 0060 end 0061 0062 %%%%%%%%%%%%%%%%%%%%%%%%%% Create cdata object %%%%%%%%%%%%%%%%%%%%%%%%%%% 0063 0064 %%%%%%%%%% val = cdata() %%%%%%%%%% 0065 % create default cdata object 0066 if nargin == 0 0067 c = init(VERSION); 0068 0069 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% one input %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0070 elseif nargin == 1 0071 0072 %%%%%%%%%%% From File %%%%%%%%%%%%%%%% 0073 if ischar(varargin{1}) 0074 0075 filename = varargin{1}; 0076 [path, name, ext, vers] = fileparts(filename); 0077 switch ext 0078 case '.mat' 0079 c = load(filename); 0080 c = c.a; 0081 case '.xml' 0082 root_node = xmlread(filename); 0083 c = ltpda_xmlread(root_node, 'cdata'); 0084 otherwise 0085 error('### Unknown file type.'); 0086 end 0087 %%%%%%%%%% val = cdata(cdata) %%%%%%%%%% 0088 elseif isa(varargin{1}, 'cdata') 0089 c = varargin{1}; 0090 0091 %%%%%%%%%% val = cdata(struct) %%%%%%%%%% 0092 elseif isstruct(varargin{1}) 0093 0094 c = init(VERSION); 0095 0096 fields = fieldnames(varargin{1}); 0097 for ii = 1:length(fields) 0098 field = fields{ii}; 0099 0100 %%% created -> time-object 0101 if strcmp(field, 'created') 0102 created = varargin{1}.created; 0103 if isstruct(created) 0104 created = time(created); 0105 end 0106 c.created = created; 0107 %%% All other 0108 else 0109 try 0110 c.(field) = varargin{1}.(field); 0111 catch 0112 error('### The field ''%s'' in the struct is not a cdata property.', field) 0113 end 0114 end 0115 end 0116 0117 %%%%%%%%%% val = cdata(plist) %%%%%%%%%% 0118 elseif isa(varargin{1}, 'plist') 0119 0120 c = init(VERSION); 0121 0122 % get possible parameters 0123 fcn = find(varargin{1}, 'fcn'); 0124 0125 y = find(varargin{1}, 'vals'); 0126 if isempty(y) 0127 y = find(varargin{1}, 'y'); 0128 end 0129 0130 % check which to use 0131 if ~isempty(fcn) 0132 % do function constructor 0133 y = eval(fcn); 0134 c.name = fcn; 0135 c.y = y; 0136 elseif ~isempty(y) 0137 % do vals constructor 0138 %- nothing to do here. 0139 c.y = y; 0140 else 0141 %% is the plist is empty then return an empty cdata object 0142 if nparams(varargin{1}) == 0 0143 else 0144 error('### unknown constructor method for cdata.'); 0145 end 0146 end 0147 0148 %%%%%%%%%% val = cdata(vals) %%%%%%%%%% 0149 %%%%%%%%%% val = cdata(y) %%%%%%%%%% 0150 else 0151 0152 c = init(VERSION); 0153 c.name = 'Data'; 0154 c.y = varargin{1}; 0155 0156 end 0157 0158 0159 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% two inputs %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0160 elseif nargin == 2 0161 0162 %%%%%%%%%%% From DATABASE 0163 if isa(varargin{1}, 'database') 0164 c = retrieve(varargin{1}, varargin{2:end}); 0165 0166 %%%%%%%%%% val = cdata(N,val) %%%%%%%%%% 0167 elseif numel(varargin{1}) == 1 0168 c = init(VERSION); 0169 c.name = 'Constant'; 0170 c.y = ones(varargin{1},1)*varargin{2}; 0171 0172 %%%%%%%%%% val = cdata(tag, val) %%%%%%%%%% 0173 else %if iscell(varargin{1}) 0174 c = init(VERSION); 0175 c.name = 'Constant'; 0176 c.x = varargin{1}; 0177 c.y = varargin{2}; 0178 end 0179 else 0180 error('### Unknown number of constructor arguments.'); 0181 end 0182 0183 % check data 0184 % c = checkCdata(c); 0185 end 0186 0187 0188 %-------------------------------------------------------------------------- 0189 % check vector has right dimensions 0190 function c = checkCdata(c) 0191 0192 x = c.y; 0193 if size(x, 1) < size(x, 2) 0194 x = x.'; 0195 end 0196 0197 c = set(c, 'y', x); 0198 end 0199