Home > classes > @ao > compute.m

compute

PURPOSE ^

COMPUTE performs the given operations on the input AOs.

SYNOPSIS ^

function varargout = compute(varargin)

DESCRIPTION ^

 COMPUTE performs the given operations on the input AOs.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: COMPUTE performs the given operations on the input AOs.

 This is a transparent wrapper for the user selected operations and as such
 doesn't add history.

 CALL:        b = compute(a)
              b = compute(a, pl)
              b = compute(a, 'a(1) + a(2)./a(3)')
              b = compute(a, {'a(1) + a(2)./a(3)', 'log10(a(1))'})

 PARAMETERS:  'Operations' - a string array describing the operations to
                             be performed. The input AOs are collected
                             together into a vector called 'a' and as
                             such should be so represented in your
                             operation description.

 If no operation is input, then the output is just a copy of the inputs.

 EXAMPLES: 1) Add the two AOs, x and y, together
              >> b = compute(x,y, plist('Operations', 'a(1) + a(2)'))
           or
              >> b = compute(x,y, 'a(1) + a(2)')

           2) Perform two operations such that the output, b, contains two AOs
              >> b = compute([x y], z, plist('Operations', {'2.*a(3)./a(1)', 'a(2)-a(1)'}))

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

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

 VERSION:     $Id: compute.m,v 1.11 2008/09/05 11:05:28 ingo Exp $

 HISTORY:     12-03-07 M Hewitson
                 Creation

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 % COMPUTE performs the given operations on the input AOs.
0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0003 %
0004 % DESCRIPTION: COMPUTE performs the given operations on the input AOs.
0005 %
0006 % This is a transparent wrapper for the user selected operations and as such
0007 % doesn't add history.
0008 %
0009 % CALL:        b = compute(a)
0010 %              b = compute(a, pl)
0011 %              b = compute(a, 'a(1) + a(2)./a(3)')
0012 %              b = compute(a, {'a(1) + a(2)./a(3)', 'log10(a(1))'})
0013 %
0014 % PARAMETERS:  'Operations' - a string array describing the operations to
0015 %                             be performed. The input AOs are collected
0016 %                             together into a vector called 'a' and as
0017 %                             such should be so represented in your
0018 %                             operation description.
0019 %
0020 % If no operation is input, then the output is just a copy of the inputs.
0021 %
0022 % EXAMPLES: 1) Add the two AOs, x and y, together
0023 %              >> b = compute(x,y, plist('Operations', 'a(1) + a(2)'))
0024 %           or
0025 %              >> b = compute(x,y, 'a(1) + a(2)')
0026 %
0027 %           2) Perform two operations such that the output, b, contains two AOs
0028 %              >> b = compute([x y], z, plist('Operations', {'2.*a(3)./a(1)', 'a(2)-a(1)'}))
0029 %
0030 % M-FILE INFO: Get information about this methods by calling
0031 %              >> ao.getInfo('compute')
0032 %
0033 %              Get information about a specified set-plist by calling:
0034 %              >> ao.getInfo('compute', 'None')
0035 %
0036 % VERSION:     $Id: compute.m,v 1.11 2008/09/05 11:05:28 ingo Exp $
0037 %
0038 % HISTORY:     12-03-07 M Hewitson
0039 %                 Creation
0040 %
0041 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0042 
0043 function varargout = compute(varargin)
0044 
0045   % Check if this is a call for parameters
0046   if utils.helper.isinfocall(varargin{:})
0047     varargout{1} = getInfo(varargin{3});
0048     return
0049   end
0050 
0051   import utils.const.*
0052   utils.helper.msg(msg.MNAME, 'running %s/%s', mfilename('class'), mfilename);
0053   
0054   % Collect input variable names
0055   in_names = cell(size(varargin));
0056   for ii = 1:nargin,in_names{ii} = inputname(ii);end
0057 
0058   % Collect all AOs and plists
0059   [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names);
0060   [pl, pl_invars] = utils.helper.collect_objects(varargin(:), 'plist', in_names);
0061 
0062   if nargout == 0
0063     error('### cohere cannot be used as a modifier. Please give an output variable.');
0064   end
0065   
0066   % Decide on a deep copy or a modify
0067   a = copy(as, nargout);
0068 
0069   % combine plists
0070   pl = combine(pl, getDefaultPlist());
0071 
0072   % Look for plist of input char
0073   ops = '';
0074   if ischar(varargin{end})
0075     ops = varargin{end};
0076   else
0077     ops = find(pl, 'Operations');
0078   end
0079 
0080   % Check we have a cell array
0081   if ischar(ops)
0082     ops = {ops};
0083   end
0084 
0085   % Loop over operations
0086   bs(length(ops),1) = ao;
0087   for jj=1:length(ops)
0088     % evaluate this operation
0089     if ops{jj}(end) ~= ';'
0090       ops{jj}(end+1) = ';';
0091     end
0092     bs(jj) = eval(ops{jj});
0093   end
0094 
0095   % Set outputs
0096   varargout{1} = bs;
0097 end
0098 
0099 %--------------------------------------------------------------------------
0100 % Get Info Object
0101 %--------------------------------------------------------------------------
0102 function ii = getInfo(varargin)
0103   if nargin == 1 && strcmpi(varargin{1}, 'None')
0104     sets = {};
0105     pl   = [];
0106   else
0107     sets = {'Default'};
0108     pl   = getDefaultPlist;
0109   end
0110   % Build info object
0111   ii = minfo(mfilename, 'ao', '', utils.const.categories.sigproc, '$Id: compute.m,v 1.11 2008/09/05 11:05:28 ingo Exp $', sets, pl);
0112 end
0113 
0114 %--------------------------------------------------------------------------
0115 % Get Default Plist
0116 %--------------------------------------------------------------------------
0117 function pl = getDefaultPlist()
0118   pl = plist('Operations', 'a');
0119 end
0120 % END
0121 
0122

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