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.10 2007/10/12 15:30:16 ingo 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 0083 %%% created -> time-object 0084 if strcmp(field, 'created') 0085 created = varargin{1}.created; 0086 if isstruct(created) 0087 created = time(created); 0088 end 0089 xy.created = created; 0090 %%% All other 0091 else 0092 try 0093 xy.(field) = varargin{1}.(field); 0094 catch 0095 error('### The field ''%s'' in the struct is not a xydata property.', field) 0096 end 0097 end 0098 end 0099 0100 %%%%%%%%%% xy = xydata(y_vector) %%%%%%%%%% 0101 else 0102 xy = init(); 0103 xy.x = 1:length(varargin{1}); 0104 xy.y = varargin{1}; 0105 end 0106 0107 %%%%%%%%%% xy = xydata(x_vector, y_vector) %%%%%%%%%% 0108 elseif nargin == 2 0109 0110 %%%%%%%%%%% From DATABASE 0111 if isa(varargin{1}, 'database') 0112 xy = retrieve(varargin{1}, varargin{2:end}); 0113 return 0114 else 0115 xy = init(); 0116 xy.x = varargin{1}; 0117 xy.y = varargin{2}; 0118 end 0119 else 0120 error('### Unknown number of constructor arguments.'); 0121 end 0122 0123 0124 %%%%%%%%%% Normalize the the x- and y-vector %%%%%%%%%% 0125 if size(xy.y,2) > size(xy.y,1) 0126 xy.y = [xy.y].'; 0127 end 0128 xy.x = reshape(xy.x, size(xy.y)); 0129 0130 0131 end % function xy = xydata(varargin) 0132 0133