Home > classes > @data2D > applyoperator.m

applyoperator

PURPOSE ^

APPLYOPERATOR applys the given operator to the two input data objects.

SYNOPSIS ^

function varargout = applyoperator(varargin)

DESCRIPTION ^

 APPLYOPERATOR applys the given operator to the two input data objects.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: APPLYOPERATOR applys the given operator to the two input
              2D data objects.

 CALL:        d = applyoperator(d1, d2, pl)

 INPUTS:      d1/2   - an ltpda_data object (cdata, tsdata, fsdata, xydata)
              pl     - a plist of configuration options

 PARAMETERS: 'op'     - the operator to apply, e.g. 'plus'

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

              Get information about a specified set-plist by calling:
              >> fsdata.getInfo('applyoperator', 'set')

 VERSION:     $Id: applyoperator.m,v 1.10 2008/08/15 13:48:20 ingo Exp $

 HISTORY:     04-02-2007 M Hewitson
                 Creation

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 % APPLYOPERATOR applys the given operator to the two input data objects.
0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0003 %
0004 % DESCRIPTION: APPLYOPERATOR applys the given operator to the two input
0005 %              2D data objects.
0006 %
0007 % CALL:        d = applyoperator(d1, d2, pl)
0008 %
0009 % INPUTS:      d1/2   - an ltpda_data object (cdata, tsdata, fsdata, xydata)
0010 %              pl     - a plist of configuration options
0011 %
0012 % PARAMETERS: 'op'     - the operator to apply, e.g. 'plus'
0013 %
0014 % M-FILE INFO: Get information about this methods by calling
0015 %              >> fsdata.getInfo('applyoperator')
0016 %
0017 %              Get information about a specified set-plist by calling:
0018 %              >> fsdata.getInfo('applyoperator', 'set')
0019 %
0020 % VERSION:     $Id: applyoperator.m,v 1.10 2008/08/15 13:48:20 ingo Exp $
0021 %
0022 % HISTORY:     04-02-2007 M Hewitson
0023 %                 Creation
0024 %
0025 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0026 
0027 function varargout = applyoperator(varargin)
0028 
0029   %%% Check if this is a call for parameters
0030   if utils.helper.isinfocall(varargin{:})
0031     varargout{1} = getInfo(varargin{3});
0032     return
0033   end
0034 
0035   % Get the objects we have in the correct order
0036   objs = [];
0037   for j=1:nargin
0038     if isa(varargin{j}, 'data2D') || isa(varargin{j}, 'cdata')
0039       objs = [objs {varargin{j}}];
0040     end
0041   end
0042 
0043   % Get data2D objects and plists
0044   [pl]   = utils.helper.collect_objects(varargin(:), 'plist');
0045 
0046   % Combine with default plist
0047   pl = combine(pl, getDefaultPlist);
0048 
0049   % Get the operator to apply
0050   op   = find(pl, 'op');
0051   axis = find(pl, 'axis');
0052 
0053   if numel(objs) ~= 2
0054     error('### data2D/applyoperator requires two input data objects to work on.');
0055   end
0056 
0057   %--------------- Add some rules here.
0058   % cdata
0059   %    1) time-base must match
0060   %    2) y dimensions must match or one must be a single value
0061   %
0062 
0063   %%% Decide the type of the output object
0064   if isa(objs{1}, 'data2D')
0065     dout = objs{1};
0066     y1 = dout.y;
0067     x1 = dout.getX;
0068     y2 = objs{2}.y;
0069     x2 = objs{2}.getX;
0070   elseif isa(objs{2}, 'data2D')
0071     dout = objs{2};
0072     y1 = objs{1}.y;
0073     x1 = objs{1}.getX;
0074     y2 = dout.y;
0075     x2 = dout.getX;
0076   else
0077     dout = objs{1};
0078     y1 = dout.y;
0079     x2 = dout.getX;
0080     y2 = objs{2}.y;
0081     x2 = objs{2}.getX;
0082   end
0083 
0084   %%% Change for the following operations the shape of the axis
0085   %%% if the shape is different
0086   if  strcmp(op, 'minus')   || ...
0087       strcmp(op, 'plus')    || ...
0088       strcmp(op, 'rdivide') || ...
0089       strcmp(op, 'times')   || ...
0090       strcmp(op, 'power')
0091     s1 = size(y1);
0092     s2 = size(y2);
0093     if s1(1) == 1 && s2(1) ~= 1
0094       y2 = y2';
0095       x2 = x2';
0096     end
0097     if s1(2) == 1 && s2(2) ~= 1
0098       y2 = y2';
0099       x2 = x2';
0100     end
0101   end
0102 
0103   %%% Decide on which axis the operation should apply
0104   switch upper(axis)
0105     case 'X'
0106       dout.setX(feval(op, x1, x2));
0107     case 'Y'
0108       dout.setY(feval(op, y1, y2));
0109     case 'XY'
0110       dout.setX(feval(op, x1, x2));
0111       dout.setY(feval(op, y1, y2));
0112     otherwise
0113       error('### Unknown axis to operate on.');
0114   end
0115 
0116   varargout{1} = dout;
0117 end
0118 
0119 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0120 %                               Local Functions                               %
0121 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0122 
0123 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0124 %
0125 % FUNCTION:    getInfo
0126 %
0127 % DESCRIPTION: Get Info Object
0128 %
0129 % HISTORY:     11-07-07 M Hewitson
0130 %                Creation.
0131 %
0132 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0133 
0134 function ii = getInfo(varargin)
0135   if nargin == 1 && strcmpi(varargin{1}, 'None')
0136     sets = {};
0137     pl   = [];
0138   else
0139     sets = {'Default'};
0140     pl   = getDefaultPlist;
0141   end
0142   % Build info object
0143   ii = minfo(mfilename, 'data2D', '', 'Internal', '$Id: applyoperator.m,v 1.10 2008/08/15 13:48:20 ingo Exp $', sets, pl);
0144 end
0145 
0146 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0147 %
0148 % FUNCTION:    getDefaultPlist
0149 %
0150 % DESCRIPTION: Get Default Plist
0151 %
0152 % HISTORY:     11-07-07 M Hewitson
0153 %                Creation.
0154 %
0155 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0156 
0157 function pl = getDefaultPlist()
0158   pl = plist('op', '', 'axis', 'y');
0159 end

Generated on Mon 25-Aug-2008 22:39:29 by m2html © 2003