Home > classes > @xyzdata > xyzdata.m

xyzdata

PURPOSE ^

XZYDATA X-Y-Z data object class constructor.

SYNOPSIS ^

function xyz = xyzdata(varargin)

DESCRIPTION ^

 XZYDATA X-Y-Z data object class constructor.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: XYZDATA X-Y-Z data object class constructor.
              Create an X-Y-Z data object.

     Properties:
       name    - name of x-y-z data object
       x       - x samples vector
       y       - y samples vector
       z       - z samples vector
       xunits  - units to interpret the x samples (e.g., seconds)
       yunits  - units to interpret the y samples (e.g., frequency)
       zunits  - units to interpret the z samples (e.g., Volts)
       version - current version of the constructor
       created - current date and time as an number

     Possible constructors:
       xyz = xyzdata()      - creates a blank xyz object
       xyz = xyzdata(y)     - creates an xyz object with the given
                              z-data.
       xyz = xydata(x,y,z)  - creates an xyz object with the given
                              (x,y,z)-data.

 HISTORY: 24-12-2007 Hewitson
             Creation

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function xyz = xyzdata(varargin)
0002 % XZYDATA X-Y-Z data object class constructor.
0003 %
0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 % DESCRIPTION: XYZDATA X-Y-Z data object class constructor.
0007 %              Create an X-Y-Z data object.
0008 %
0009 %     Properties:
0010 %       name    - name of x-y-z data object
0011 %       x       - x samples vector
0012 %       y       - y samples vector
0013 %       z       - z samples vector
0014 %       xunits  - units to interpret the x samples (e.g., seconds)
0015 %       yunits  - units to interpret the y samples (e.g., frequency)
0016 %       zunits  - units to interpret the z samples (e.g., Volts)
0017 %       version - current version of the constructor
0018 %       created - current date and time as an number
0019 %
0020 %     Possible constructors:
0021 %       xyz = xyzdata()      - creates a blank xyz object
0022 %       xyz = xyzdata(y)     - creates an xyz object with the given
0023 %                              z-data.
0024 %       xyz = xydata(x,y,z)  - creates an xyz object with the given
0025 %                              (x,y,z)-data.
0026 %
0027 % HISTORY: 24-12-2007 Hewitson
0028 %             Creation
0029 %
0030 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0031 
0032 VERSION  = '$Id: xyzdata.html,v 1.7 2008/03/31 10:27:43 hewitson Exp $';
0033 CATEGORY = 'Constructor';
0034 
0035 %%%%%   Is this a 'Params' call?     %%%%%
0036 if  nargin == 2 && isa(varargin{1}, 'xyzdata') && ischar(varargin{2})
0037   if strcmp(varargin{2}, 'Params')
0038     xyz = plist();
0039     return
0040   elseif strcmp(varargin{2}, 'Version')
0041     xyz = VERSION;
0042     return
0043   elseif strcmp(varargin{2}, 'Category')
0044     xyz = CATEGORY;
0045     return
0046   end
0047 end
0048 
0049 %%%%%%%%%%%%%%%%%%%%%%%%   define xydata properties   %%%%%%%%%%%%%%%%%%%%%%%%%
0050 
0051   function xyz = init(version)
0052     xyz.name    = 'None';
0053     xyz.x       = [];
0054     xyz.y       = [];
0055     xyz.z       = [];
0056     xyz.xunits  = '';
0057     xyz.yunits  = '';
0058     xyz.zunits  = '';
0059     xyz.version = version;
0060     xyz.created = time;
0061     xyz         = class(xyz, 'xyzdata');
0062   end
0063 
0064 %%%%%%%%%%%%%%%%%%%%%%%%%%   Create xydata object   %%%%%%%%%%%%%%%%%%%%%%%%%%%
0065 
0066 %%%%%%%%%%   xy = xydata()   %%%%%%%%%%
0067 % create default xydata object
0068 if nargin == 0
0069   xyz = init(VERSION);
0070 
0071 elseif nargin == 1
0072 
0073   %%%%%%%%%%% From File %%%%%%%%%%%%%%%%
0074   if ischar(varargin{1})
0075 
0076     filename = varargin{1};
0077     [path, name, ext, vers] = fileparts(filename);
0078     switch ext
0079       case '.mat'
0080         xyz = load(filename);
0081         xyz = xyz.a;
0082       case '.xml'
0083         root_node = xmlread(filename);
0084         xyz = ltpda_xmlread(root_node, 'xyzdata');
0085       otherwise
0086         error('### Unknown file type.');
0087     end
0088   %%%%%%%%%%   xy = xydata(xydata)   %%%%%%%%%%
0089   elseif isa(varargin{1}, 'xyzdata')
0090     xyz = varargin{1};
0091 
0092   %%%%%%%%%%   xy = xydata(struct)   %%%%%%%%%%
0093   elseif isstruct(varargin{1})
0094 
0095     xyz = init(VERSION);
0096 
0097     fields = fieldnames(varargin{1});
0098     for ii = 1:length(fields)
0099       field = fields{ii};
0100 
0101       %%% created -> time-object
0102       if strcmp(field, 'created')
0103         created       = varargin{1}.created;
0104         if isstruct(created)
0105           created = time(created);
0106         end
0107         xyz.created     = created;
0108       %%% All other
0109       else
0110         try
0111           xyz.(field) = varargin{1}.(field);
0112         catch
0113           error('### The field ''%s'' in the struct is not a xydata property.', field)
0114         end
0115       end
0116     end
0117 
0118   %%%%%%%%%%   xyz = xyzdata(y_vector)   %%%%%%%%%%
0119   elseif isnumeric(varargin{1}) && length(varargin{1}) > 1
0120     xyz   = init(VERSION);
0121     xyz.x = 1:size(varargin{1}, 1);
0122     xyz.y = 1:size(varargin{1}, 2);
0123     xyz.z = varargin{1};
0124 
0125   %%%%%%%%%%  ts = xydata(plist)   %%%%%%%%%%
0126   elseif isa(varargin{1}, 'plist')
0127     %% is the plist is empty then return an empty xyzdata object
0128     if nparams(varargin{1}) == 0
0129       xyz = init(VERSION);
0130     else
0131       error('### Unknown xyzdata constructor method.');
0132     end
0133 
0134   else
0135     error('### Unknown xyzdata constructor method.');
0136   end
0137 
0138 %%%%%%%%%%   xyz = xydata(x_vector, y_vector)   %%%%%%%%%%
0139 elseif nargin == 2
0140 
0141   %%%%%%%%%%% From DATABASE
0142   if isa(varargin{1}, 'database')
0143     xyz = retrieve(varargin{1}, varargin{2:end});
0144   else
0145     error('### Unknown constructor.');
0146   end
0147 elseif nargin == 3
0148   xyz   = init(VERSION);
0149   xyz.x = varargin{1};
0150   xyz.y = varargin{2};
0151   xyz.z = varargin{3};
0152 else
0153   error('### Unknown number of constructor arguments.');
0154 end
0155 
0156 
0157 %%%%%%%%%%   Normalize the the x- and y-vector   %%%%%%%%%%
0158 
0159 nx = size(xyz.z, 2);
0160 ny = size(xyz.z, 1);
0161 
0162 if length(xyz.x) ~= nx
0163   error('### X-vector has wrong length.');
0164 end
0165 if length(xyz.y) ~= ny
0166   error('### Y-vector has wrong length.');
0167 end
0168 if size(xyz.y,2) > size(xyz.y,1)
0169   xyz.y = [xyz.y].';
0170 end
0171 if size(xyz.x,2) > size(xyz.x,1)
0172   xyz.x = [xyz.x].';
0173 end
0174 
0175 
0176 
0177 end % function xy = xydata(varargin)
0178 
0179

Generated on Mon 31-Mar-2008 12:20:24 by m2html © 2003