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 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

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

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 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.14 2008/02/13 12:58:11 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()
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();
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();
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   else
0116     xy   = init();
0117     xy.x = 1:length(varargin{1});
0118     xy.y = varargin{1};
0119   end
0120 
0121 %%%%%%%%%%   xy = xydata(x_vector, y_vector)   %%%%%%%%%%
0122 elseif nargin == 2
0123 
0124   %%%%%%%%%%% From DATABASE
0125   if isa(varargin{1}, 'database')
0126     xy = retrieve(varargin{1}, varargin{2:end});
0127     return
0128   else
0129     xy   = init();
0130     xy.x = varargin{1};
0131     xy.y = varargin{2};
0132   end
0133 else
0134   error('### Unknown number of constructor arguments.');
0135 end
0136 
0137 
0138 %%%%%%%%%%   Normalize the the x- and y-vector   %%%%%%%%%%
0139 if size(xy.y,2) > size(xy.y,1)
0140   xy.y = [xy.y].';
0141 end
0142 xy.x = reshape(xy.x, size(xy.y));
0143 
0144 
0145 end % function xy = xydata(varargin)
0146 
0147

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