XYDATA X-Y data object class constructor. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: XYDATA X-Y data object class constructor. Create an X-Y data object. Properties: name - name of time-series object x - x samples vector y - y samples vector xunits - units to interpret the time samples (e.g., seconds) yunits - units to interpret the data samples (e.g., Volts) version - current version of the constructor created - current date and time as an number Possible constructors: xy = xydata() - creates a blank time-series object xy = xydata(y) - creates a time-series object with the given x-data. xy = xydata(x,y) - creates a time-series object with the given (x,y)-data. HISTORY: 30-01-2007 Hewitson Creation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001 function xy = xydata(varargin) 0002 % XYDATA X-Y data object class constructor. 0003 % 0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0005 % 0006 % DESCRIPTION: XYDATA X-Y data object class constructor. 0007 % Create an X-Y data object. 0008 % 0009 % Properties: 0010 % name - name of time-series object 0011 % x - x samples vector 0012 % y - y samples vector 0013 % xunits - units to interpret the time samples (e.g., seconds) 0014 % yunits - units to interpret the data samples (e.g., Volts) 0015 % version - current version of the constructor 0016 % created - current date and time as an number 0017 % 0018 % Possible constructors: 0019 % xy = xydata() - creates a blank time-series object 0020 % xy = xydata(y) - creates a time-series object with the given 0021 % x-data. 0022 % xy = xydata(x,y) - creates a time-series object with the given 0023 % (x,y)-data. 0024 % 0025 % HISTORY: 30-01-2007 Hewitson 0026 % Creation 0027 % 0028 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0029 0030 VERSION = '$Id: xydata.m,v 1.9 2007/08/31 17:40:08 hewitson Exp $'; 0031 0032 %%%%%%%%%%%%%%%%%%%%%%%% define xydata properties %%%%%%%%%%%%%%%%%%%%%%%%% 0033 0034 function xy = init() 0035 xy.name = 'None'; 0036 xy.x = []; 0037 xy.y = []; 0038 xy.xunits = ''; 0039 xy.yunits = ''; 0040 xy.version = VERSION; 0041 xy.created = time; 0042 xy = class(xy, 'xydata'); 0043 end 0044 0045 %%%%%%%%%%%%%%%%%%%%%%%%%% Create xydata object %%%%%%%%%%%%%%%%%%%%%%%%%%% 0046 0047 %%%%%%%%%% xy = xydata() %%%%%%%%%% 0048 % create default xydata object 0049 if nargin == 0 0050 xy = init(); 0051 0052 elseif nargin == 1 0053 0054 %%%%%%%%%% Create from XML fragment %%%%%%%%%%% 0055 if isa(varargin{1}, 'org.apache.xerces.dom.DeferredElementImpl') 0056 xy = fromxml(varargin{1}); 0057 %%%%%%%%%%% From File %%%%%%%%%%%%%%%% 0058 elseif ischar(varargin{1}) 0059 0060 filename = varargin{1}; 0061 [path, name, ext, vers] = fileparts(filename); 0062 switch ext 0063 case '.mat' 0064 xy = load(filename); 0065 case '.xml' 0066 xy = xmlparse(xydata, filename); 0067 otherwise 0068 error('### Unknown file type.'); 0069 end 0070 %%%%%%%%%% xy = xydata(xydata) %%%%%%%%%% 0071 elseif isa(varargin{1}, 'xydata') 0072 xy = varargin{1}; 0073 0074 %%%%%%%%%% xy = xydata(struct) %%%%%%%%%% 0075 elseif isstruct(varargin{1}) 0076 0077 xy = init(); 0078 0079 fields = fieldnames(varargin{1}); 0080 for ii = 1:length(fields) 0081 field = fields{ii}; 0082 try 0083 xy.(field) = varargin{1}.(field); 0084 catch 0085 error('### The field ''%s'' in the struct is not a xydata property.', field) 0086 end 0087 end 0088 0089 %%%%%%%%%% xy = xydata(y_vector) %%%%%%%%%% 0090 else 0091 xy = init(); 0092 xy.x = 1:length(varargin{1}); 0093 xy.y = varargin{1}; 0094 end 0095 0096 %%%%%%%%%% xy = xydata(x_vector, y_vector) %%%%%%%%%% 0097 elseif nargin == 2 0098 0099 %%%%%%%%%%% From DATABASE 0100 if isa(varargin{1}, 'database') 0101 xy = retrieve(varargin{1}, varargin{2:end}); 0102 return 0103 else 0104 xy = init(); 0105 xy.x = varargin{1}; 0106 xy.y = varargin{2}; 0107 end 0108 else 0109 error('### Unknown number of constructor arguments.'); 0110 end 0111 0112 0113 %%%%%%%%%% Normalize the the x- and y-vector %%%%%%%%%% 0114 if size(xy.y,2) > size(xy.y,1) 0115 xy.y = [xy.y].'; 0116 end 0117 xy.x = reshape(xy.x, size(xy.y)); 0118 0119 0120 end % function xy = xydata(varargin) 0121 0122