Home > classes > @ao > complex.m

complex

PURPOSE ^

COMPLEX overloads the complex operator for Analysis objects.

SYNOPSIS ^

function varargout = complex(varargin)

DESCRIPTION ^

 COMPLEX overloads the complex operator for Analysis objects.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: COMPLEX overloads the complex operator for Analysis objects.
              A3 = COMPLEX(A1,A2) returns the complex result A1 + A2i,
              where A1 and A2 are identically sized real arrays.

 CALL:        ao_out = complex(a1, a2);

 M-FILE INFO: Get information about this methods by calling
              >> ao.getInfo('complex')

              Get information about a specified set-plist by calling:
              >> ao.getInfo('complex', 'None')

 VERSION:     $Id: complex.m,v 1.22 2008/09/05 14:13:27 hewitson Exp $

 HISTORY:     20-08-2007 Diepholz
                 Creation

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 % COMPLEX overloads the complex operator for Analysis objects.
0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0003 %
0004 % DESCRIPTION: COMPLEX overloads the complex operator for Analysis objects.
0005 %              A3 = COMPLEX(A1,A2) returns the complex result A1 + A2i,
0006 %              where A1 and A2 are identically sized real arrays.
0007 %
0008 % CALL:        ao_out = complex(a1, a2);
0009 %
0010 % M-FILE INFO: Get information about this methods by calling
0011 %              >> ao.getInfo('complex')
0012 %
0013 %              Get information about a specified set-plist by calling:
0014 %              >> ao.getInfo('complex', 'None')
0015 %
0016 % VERSION:     $Id: complex.m,v 1.22 2008/09/05 14:13:27 hewitson Exp $
0017 %
0018 % HISTORY:     20-08-2007 Diepholz
0019 %                 Creation
0020 %
0021 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0022 
0023 function varargout = complex(varargin)
0024 
0025   % Check if this is a call for parameters
0026   if utils.helper.isinfocall(varargin{:})
0027     varargout{1} = getInfo(varargin{3});
0028     return
0029   end
0030 
0031   import utils.const.*
0032   utils.helper.msg(msg.MNAME, 'running %s/%s', mfilename('class'), mfilename);
0033 
0034   % Collect input variable names
0035   in_names = cell(size(varargin));
0036   for ii = 1:nargin,in_names{ii} = inputname(ii);end
0037 
0038   % Collect all AOs and plists
0039   [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names);
0040 
0041   % Decide on a deep copy or a modify
0042   bs = copy(as, nargout);
0043 
0044   % Check input arguments number
0045   if length(bs) ~= 2
0046     error ('### Incorrect inputs. Please enter 2 AOs');
0047   end
0048 
0049   % Only support data2D or cdata for now
0050   if isa(bs(1).data, 'data3D') || isa(bs(2).data, 'data3D')
0051     error('### 3D data objects are currently not supported.');
0052   end
0053 
0054   % Check for the same data.
0055   if ~strcmp(class(bs(1).data), class(bs(2).data))
0056     error ('### The data class of the two AOs must be the same. (%s <-> %s)', ...
0057       class(bs(1).data), class(bs(2).data));
0058   end
0059 
0060   % Check for the same sampe rate
0061   fields = fieldnames(bs(1).data);
0062   if ismember('fs', fields)
0063     if bs(1).data.fs ~= bs(2).data.fs
0064       error('### The sample rate of the two AOs is not the same. Please resample one of them.');
0065     end
0066   end
0067 
0068   % Check the length of the AO's
0069   if length(bs(1).data.getY) ~= length(bs(2).data.getY) || length(bs(1).data.getX) ~= length(bs(2).data.getX)
0070     error ('### The length of the data vectors must be the same.')
0071   end
0072 
0073   % The x vector should be the same
0074   if ~isequal(bs(1).data.getX, bs(2).data.getX)
0075     error('### The two data series should have the same x values.');
0076   end
0077 
0078   % The time should be the same
0079   if ismember('t0', fields)
0080     if bs(1).data.t0.utc_epoch_milli ~= bs(2).data.t0.utc_epoch_milli
0081       error('### The two data series don''t start at the same time.');
0082     end
0083   end
0084 
0085   % The x units should match
0086   if ismember('xunits', fields)
0087     if bs(1).data.xunits ~= bs(2).data.xunits
0088       error('### The two data series should have the same x units');
0089     end
0090   end
0091 
0092   % Copy object 1 for the output
0093   bs(1).data.setY(complex(bs(1).data.getY, bs(2).data.getY));
0094   if ismember('yunits', fields)
0095     if bs(1).data.yunits == bs(2).data.yunits
0096       bs(1).setYunits(bs(1).data.yunits, 'internal');
0097     else
0098       error('### Can''t combine data with different units');
0099     end
0100   end
0101 
0102   % Add history
0103   bs(1).addHistory(getInfo, getDefaultPlist, ao_invars, [bs(1).hist bs(2).hist]);
0104 
0105   % Set name
0106   bs(1).setName(sprintf('complex(%s, %s)', ao_invars{1}, ao_invars{2}), 'internal');
0107 
0108   % Set output
0109   varargout{1} = bs(1);
0110 end
0111 
0112 %--------------------------------------------------------------------------
0113 % Get Info Object
0114 %--------------------------------------------------------------------------
0115 function ii = getInfo(varargin)
0116   if nargin == 1 && strcmpi(varargin{1}, 'None')
0117     sets = {};
0118     pl   = [];
0119   else
0120     sets = {'Default'};
0121     pl   = getDefaultPlist;
0122   end
0123   % Build info object
0124   ii = minfo(mfilename, 'ao', '', utils.const.categories.op, '$Id: complex.m,v 1.22 2008/09/05 14:13:27 hewitson Exp $', sets, pl);
0125 end
0126 
0127 %--------------------------------------------------------------------------
0128 % Get Default Plist
0129 %--------------------------------------------------------------------------
0130 function pl = getDefaultPlist()
0131   pl = plist();
0132 end
0133

Generated on Mon 08-Sep-2008 13:18:47 by m2html © 2003