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 time-series object
       x       - x samples vector
       y       - y samples vector
       z       - z samples vector
       xunits  - units to interpret the time samples (e.g., seconds)
       yunits  - units to interpret the data samples (e.g., frequency)
       zunits  - 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:
       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 time-series object
0011 %       x       - x samples vector
0012 %       y       - y samples vector
0013 %       z       - z samples vector
0014 %       xunits  - units to interpret the time samples (e.g., seconds)
0015 %       yunits  - units to interpret the data samples (e.g., frequency)
0016 %       zunits  - units to interpret the data 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.m,v 1.3 2008/02/13 13:22:45 mauro 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()
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();
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();
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   else
0120     xyz   = init();
0121     xyz.x = 1:size(varargin{1}, 1);
0122     xyz.y = 1:size(varargin{1}, 2);
0123     xyz.z = varargin{1};
0124   end
0125 
0126 %%%%%%%%%%   xy = xydata(x_vector, y_vector)   %%%%%%%%%%
0127 elseif nargin == 2
0128 
0129   %%%%%%%%%%% From DATABASE
0130   if isa(varargin{1}, 'database')
0131     xyz = retrieve(varargin{1}, varargin{2:end});
0132   else
0133     error('### Unknown constructor.');
0134   end
0135 elseif nargin == 3
0136   xyz   = init();
0137   xyz.x = varargin{1};
0138   xyz.y = varargin{2};
0139   xyz.z = varargin{3};
0140 else
0141   error('### Unknown number of constructor arguments.');
0142 end
0143 
0144 
0145 %%%%%%%%%%   Normalize the the x- and y-vector   %%%%%%%%%%
0146 
0147 nx = size(xyz.z, 2);
0148 ny = size(xyz.z, 1);
0149 
0150 if length(xyz.x) ~= nx
0151   error('### X-vector has wrong length.');
0152 end
0153 if length(xyz.y) ~= ny
0154   error('### Y-vector has wrong length.');
0155 end
0156 if size(xyz.y,2) > size(xyz.y,1)
0157   xyz.y = [xyz.y].';
0158 end
0159 if size(xyz.x,2) > size(xyz.x,1)
0160   xyz.x = [xyz.x].';
0161 end
0162 
0163 
0164 
0165 end % function xy = xydata(varargin)
0166 
0167

Generated on Fri 07-Mar-2008 15:46:43 by m2html © 2003