Home > classes > @xydata > xydata.m

xydata

PURPOSE ^

XYDATA X-Y data object class constructor.

SYNOPSIS ^

function xy = xydata(varargin)

DESCRIPTION ^

 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 x-y data object
       x       - x samples vector
       y       - y samples vector
       xunits  - units to interpret the x samples (e.g., seconds)
       yunits  - units to interpret the y 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

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

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 x-y data object
0011 %       x       - x samples vector
0012 %       y       - y samples vector
0013 %       xunits  - units to interpret the x samples (e.g., seconds)
0014 %       yunits  - units to interpret the y 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.17 2008/03/17 09:16:37 mauro Exp $';
0031 CATEGORY = 'Constructor';
0032 
0033 %%%%%   Is this a 'Params' call?     %%%%%
0034 if  nargin == 2 && ischar(varargin{2})
0035   if strcmp(varargin{2}, 'Params')
0036     xy = plist();
0037     return
0038   elseif strcmp(varargin{2}, 'Version')
0039     xy = VERSION;
0040     return
0041   elseif strcmp(varargin{2}, 'Category')
0042     xy = CATEGORY;
0043     return
0044   end
0045 end
0046 
0047 %%%%%%%%%%%%%%%%%%%%%%%%   define xydata properties   %%%%%%%%%%%%%%%%%%%%%%%%%
0048 
0049   function xy = init(version)
0050     xy.name    = 'None';
0051     xy.x       = [];
0052     xy.y       = [];
0053     xy.xunits  = '';
0054     xy.yunits  = '';
0055     xy.version = version;
0056     xy.created = time;
0057     xy         = class(xy, 'xydata');
0058   end
0059 
0060 %%%%%%%%%%%%%%%%%%%%%%%%%%   Create xydata object   %%%%%%%%%%%%%%%%%%%%%%%%%%%
0061 
0062 %%%%%%%%%%   xy = xydata()   %%%%%%%%%%
0063 % create default xydata object
0064 if nargin == 0
0065   xy = init(VERSION);
0066 
0067 elseif nargin == 1
0068 
0069   %%%%%%%%%%% From File %%%%%%%%%%%%%%%%
0070   if ischar(varargin{1})
0071 
0072     filename = varargin{1};
0073     [path, name, ext, vers] = fileparts(filename);
0074     switch ext
0075       case '.mat'
0076         xy = load(filename);
0077         xy = xy.a;
0078       case '.xml'
0079         root_node = xmlread(filename);
0080         xy = ltpda_xmlread(root_node, 'xydata');
0081       otherwise
0082         error('### Unknown file type.');
0083     end
0084   %%%%%%%%%%   xy = xydata(xydata)   %%%%%%%%%%
0085   elseif isa(varargin{1}, 'xydata')
0086     xy = varargin{1};
0087 
0088   %%%%%%%%%%   xy = xydata(struct)   %%%%%%%%%%
0089   elseif isstruct(varargin{1})
0090 
0091     xy = init(VERSION);
0092 
0093     fields = fieldnames(varargin{1});
0094     for ii = 1:length(fields)
0095       field = fields{ii};
0096 
0097       %%% created -> time-object
0098       if strcmp(field, 'created')
0099         created       = varargin{1}.created;
0100         if isstruct(created)
0101           created = time(created);
0102         end
0103         xy.created     = created;
0104       %%% All other
0105       else
0106         try
0107           xy.(field) = varargin{1}.(field);
0108         catch
0109           error('### The field ''%s'' in the struct is not a xydata property.', field)
0110         end
0111       end
0112     end
0113 
0114   %%%%%%%%%%   xy = xydata(y_vector)   %%%%%%%%%%
0115   elseif isnumeric(varargin{1}) && length(varargin{1}) > 1
0116     xy   = init(VERSION);
0117     xy.x = 1:length(varargin{1});
0118     xy.y = varargin{1};
0119 
0120   %%%%%%%%%%  ts = xydata(plist)   %%%%%%%%%%
0121   elseif isa(varargin{1}, 'plist')
0122     %% is the plist is empty then return an empty xydata object
0123     if nparams(varargin{1}) == 0
0124       xy = init(VERSION);
0125     else
0126       error('### Unknown xydata constructor method.');
0127     end
0128 
0129   else
0130     error('### Unknown xydata constructor method.');
0131   end
0132 
0133 %%%%%%%%%%   xy = xydata(x_vector, y_vector)   %%%%%%%%%%
0134 elseif nargin == 2
0135 
0136   %%%%%%%%%%% From DATABASE
0137   if isa(varargin{1}, 'database')
0138     xy = retrieve(varargin{1}, varargin{2:end});
0139     return
0140   else
0141     xy   = init(VERSION);
0142     xy.x = varargin{1};
0143     xy.y = varargin{2};
0144   end
0145 else
0146   error('### Unknown number of constructor arguments.');
0147 end
0148 
0149 
0150 %%%%%%%%%%   Normalize the the x- and y-vector   %%%%%%%%%%
0151 if size(xy.y,2) > size(xy.y,1)
0152   xy.y = [xy.y].';
0153 end
0154 xy.x = reshape(xy.x, size(xy.y));
0155 
0156 
0157 end % function xy = xydata(varargin)
0158 
0159

Generated on Mon 31-Mar-2008 13:54:54 by m2html © 2003