


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 xy-data object
xy = xydata(y) - creates an xy data object with the given
y-data.
xy = xydata(x,y) - creates an xy-data 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 xy-data object 0020 % xy = xydata(y) - creates an xy data object with the given 0021 % y-data. 0022 % xy = xydata(x,y) - creates an xy-data 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.12 2007/12/24 19:49:09 hewitson Exp $'; 0031 0032 %%%%% Is this a 'Params' call? %%%%% 0033 if nargin == 2 && ischar(varargin{2}) 0034 if strcmp(varargin{2}, 'Params') 0035 xy = plist(); 0036 return 0037 elseif strcmp(varargin{2}, 'Version') 0038 xy = VERSION; 0039 return 0040 end 0041 end 0042 0043 %%%%%%%%%%%%%%%%%%%%%%%% define xydata properties %%%%%%%%%%%%%%%%%%%%%%%%% 0044 0045 function xy = init() 0046 xy.name = 'None'; 0047 xy.x = []; 0048 xy.y = []; 0049 xy.xunits = ''; 0050 xy.yunits = ''; 0051 xy.version = VERSION; 0052 xy.created = time; 0053 xy = class(xy, 'xydata'); 0054 end 0055 0056 %%%%%%%%%%%%%%%%%%%%%%%%%% Create xydata object %%%%%%%%%%%%%%%%%%%%%%%%%%% 0057 0058 %%%%%%%%%% xy = xydata() %%%%%%%%%% 0059 % create default xydata object 0060 if nargin == 0 0061 xy = init(); 0062 0063 elseif nargin == 1 0064 0065 %%%%%%%%%% Create from XML fragment %%%%%%%%%%% 0066 if isa(varargin{1}, 'org.apache.xerces.dom.DeferredElementImpl') 0067 xy = fromxml(varargin{1}); 0068 %%%%%%%%%%% From File %%%%%%%%%%%%%%%% 0069 elseif ischar(varargin{1}) 0070 0071 filename = varargin{1}; 0072 [path, name, ext, vers] = fileparts(filename); 0073 switch ext 0074 case '.mat' 0075 xy = load(filename); 0076 xy = xy.a; 0077 case '.xml' 0078 xy = xmlparse(xydata, filename); 0079 otherwise 0080 error('### Unknown file type.'); 0081 end 0082 %%%%%%%%%% xy = xydata(xydata) %%%%%%%%%% 0083 elseif isa(varargin{1}, 'xydata') 0084 xy = varargin{1}; 0085 0086 %%%%%%%%%% xy = xydata(struct) %%%%%%%%%% 0087 elseif isstruct(varargin{1}) 0088 0089 xy = init(); 0090 0091 fields = fieldnames(varargin{1}); 0092 for ii = 1:length(fields) 0093 field = fields{ii}; 0094 0095 %%% created -> time-object 0096 if strcmp(field, 'created') 0097 created = varargin{1}.created; 0098 if isstruct(created) 0099 created = time(created); 0100 end 0101 xy.created = created; 0102 %%% All other 0103 else 0104 try 0105 xy.(field) = varargin{1}.(field); 0106 catch 0107 error('### The field ''%s'' in the struct is not a xydata property.', field) 0108 end 0109 end 0110 end 0111 0112 %%%%%%%%%% xy = xydata(y_vector) %%%%%%%%%% 0113 else 0114 xy = init(); 0115 xy.x = 1:length(varargin{1}); 0116 xy.y = varargin{1}; 0117 end 0118 0119 %%%%%%%%%% xy = xydata(x_vector, y_vector) %%%%%%%%%% 0120 elseif nargin == 2 0121 0122 %%%%%%%%%%% From DATABASE 0123 if isa(varargin{1}, 'database') 0124 xy = retrieve(varargin{1}, varargin{2:end}); 0125 return 0126 else 0127 xy = init(); 0128 xy.x = varargin{1}; 0129 xy.y = varargin{2}; 0130 end 0131 else 0132 error('### Unknown number of constructor arguments.'); 0133 end 0134 0135 0136 %%%%%%%%%% Normalize the the x- and y-vector %%%%%%%%%% 0137 if size(xy.y,2) > size(xy.y,1) 0138 xy.y = [xy.y].'; 0139 end 0140 xy.x = reshape(xy.x, size(xy.y)); 0141 0142 0143 end % function xy = xydata(varargin) 0144 0145