Home > classes > @ao > sum.m

sum

PURPOSE ^

SUM overloads the sum operator for Analysis objects. Compute the sum value.

SYNOPSIS ^

function ao_out = sum (varargin)

DESCRIPTION ^

 SUM overloads the sum operator for Analysis objects. Compute the sum value.

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

 DESCRIPTION: SUM overloads the sum operator for Analysis objects.
              Compute the sum value.
              SUM(ao) is the sum value of the elements in ao.data.

 CALL: ao_out = sum(ao_in);
       ao_out = sum(ao_in, dim);
       ao_out = sum(ao_in, pl);
       ao_out = sum(ao1, pl1, ao_vector, ao_matrix, pl2);

 POSSIBLE VALUES: ao_in  = [ao2 ao3]
                  ao_in  = ao_vector
                  ao_in  = ao_matrix

 PARAMETER LIST:  <key>           <value>             <description>
                  'dim'          1 or 2 or 3 ...    takes the sum along the
                                                    dimension dim
                          tsdata  fsdata  xydata
                 'xdata'   't'     'f'      'x'     compute the sum of the x-axis
                 'ydata'   'x'     'xx'     'y'     compute the sum of the y-axis

                 The following call returns a parameter list object that
                 contains the default parameter values:

                 >> pl = sum(ao, 'Params')

 HISTORY: 25-05-2007 Diepholz
             Creation

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function ao_out = sum (varargin)
0002 % SUM overloads the sum operator for Analysis objects. Compute the sum value.
0003 %
0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 % DESCRIPTION: SUM overloads the sum operator for Analysis objects.
0007 %              Compute the sum value.
0008 %              SUM(ao) is the sum value of the elements in ao.data.
0009 %
0010 % CALL: ao_out = sum(ao_in);
0011 %       ao_out = sum(ao_in, dim);
0012 %       ao_out = sum(ao_in, pl);
0013 %       ao_out = sum(ao1, pl1, ao_vector, ao_matrix, pl2);
0014 %
0015 % POSSIBLE VALUES: ao_in  = [ao2 ao3]
0016 %                  ao_in  = ao_vector
0017 %                  ao_in  = ao_matrix
0018 %
0019 % PARAMETER LIST:  <key>           <value>             <description>
0020 %                  'dim'          1 or 2 or 3 ...    takes the sum along the
0021 %                                                    dimension dim
0022 %                          tsdata  fsdata  xydata
0023 %                 'xdata'   't'     'f'      'x'     compute the sum of the x-axis
0024 %                 'ydata'   'x'     'xx'     'y'     compute the sum of the y-axis
0025 %
0026 %                 The following call returns a parameter list object that
0027 %                 contains the default parameter values:
0028 %
0029 %                 >> pl = sum(ao, 'Params')
0030 %
0031 % HISTORY: 25-05-2007 Diepholz
0032 %             Creation
0033 %
0034 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0035 
0036 VERSION  = '$Id: sum.m,v 1.5 2007/10/24 17:35:28 ingo Exp $';
0037 ao_out   = [];
0038 pl       = plist();
0039 
0040 % Check if this is a call for parameters
0041 if nargin == 2
0042   if isa(varargin{1}, 'ao') && ischar(varargin{2})
0043     in = char(varargin{2});
0044     if strcmp(in, 'Params')
0045       ao_out = getDefaultPL();
0046       return
0047     elseif strcmp(in, 'Version')
0048       ao_out = VERSION;
0049       return
0050     end
0051   end
0052 end
0053 
0054 %% store the input ao's in the vector: ao_set
0055 ao_set = [];
0056 for i=1:nargin
0057   a = varargin{i};
0058   if isa(a, 'ao')
0059     ao_set  = [ao_set a];
0060   elseif isa(varargin{i}, 'plist')
0061     pl = [pl varargin{i}];
0062   elseif isnumeric(varargin{i})
0063     pl = [pl plist(param('dim', varargin{i}))];
0064   end
0065 end
0066 
0067 if ~isempty (pl)
0068   pl = combine(pl);
0069 end
0070 
0071 %% go through analysis objects
0072 for j=1:numel(ao_set)
0073   a = ao_set(j);
0074 
0075   [h, sum_data] = single_operation(a.data, 'sum', pl);
0076 
0077   %% Add the history from the ao object to the history
0078   h = set(h, 'inhists', [a.hist]);
0079 
0080   %% Set the var_name to the history
0081   if (j <= nargin)
0082     if (isempty (inputname(j)))
0083       h = set(h, 'invars', cellstr('no var_name'));
0084     else
0085       h = set(h, 'invars', cellstr(inputname(j)));
0086     end
0087   else
0088     h = set(h, 'invars', cellstr('no var_name'));
0089   end
0090 
0091   % convert to cdata type
0092   sum_x    = [];
0093   sum_y    = [];
0094 
0095   do_xdata = find(pl, 'xdata');
0096   do_ydata = find(pl, 'ydata');
0097 
0098   %% Is no axis entry in the parameter list
0099   %% then set the default axis = xdata
0100   if isempty(do_xdata) && isempty(do_ydata)
0101     do_ydata = 'yes';
0102   end
0103 
0104   %% Get the operation result. It is stored in the individual axis
0105   pl_get_axis = plist([param('xdata', do_xdata) param('ydata', do_ydata)]);
0106   [sum_x, sum_y] = get_xy_values(sum_data, pl_get_axis);
0107 
0108   sum_cdata = cdata([sum_x sum_y]);
0109   sum_cdata = set (sum_cdata, 'name', sum_data.name);
0110   sum_cdata = set (sum_cdata, 'xunits', sum_data.xunits);
0111   sum_cdata = set (sum_cdata, 'yunits', sum_data.yunits);
0112 
0113   %% create a new analysis objects
0114   new_ao = a;
0115   new_ao = ao  (sum_cdata, h);
0116   new_ao = set (new_ao, 'name', sprintf('sum(%s)',a.name) );
0117 
0118   ao_out = [ao_out new_ao];
0119 
0120 end
0121 
0122 % Reshape the ouput to the same size of the input
0123 ao_out = reshape(ao_out, size(ao_set));
0124 
0125 %% Get default params
0126 function plo = getDefaultPL()
0127 
0128 plo = plist();
0129 plo = append(plo, param('xdata', ''));
0130 plo = append(plo, param('ydata', ''));
0131 plo = append(plo, param('dim',   []));
0132 
0133 
0134 % END

Generated on Thu 01-Nov-2007 09:42:34 by m2html © 2003