Home > classes > @xyzdata > xyzdata.m

xyzdata

PURPOSE ^

XZYDATA X-Y-Z data object class constructor.

SYNOPSIS ^

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

Generated on Tue 22-Jan-2008 10:39:13 by m2html © 2003