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

 HISTORY: 25-05-2007 Diepholz
             Creation

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

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 % HISTORY: 25-05-2007 Diepholz
0027 %             Creation
0028 %
0029 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0030 
0031 ALGONAME = mfilename;
0032 VERSION  = '$Id: sum.html,v 1.1 2007/06/08 14:15:03 hewitson Exp $';
0033 ao_out   = [];
0034 pl       = plist();
0035 option   = '';
0036 
0037 %% store the input ao's in the vector: ao_set
0038 ao_set = [];
0039 for i=1:nargin
0040   a = varargin{i};
0041   if isa(a, 'ao')
0042     [m,n] = size(a);
0043     for i = 1:m
0044       for j = 1:n
0045         ao_set  = [ao_set a(i,j)];
0046       end
0047     end
0048   elseif isa(varargin{i}, 'plist')
0049     pl = [pl varargin{i}];
0050   elseif isnumeric(varargin{i})
0051     pl = [pl plist(param('dim', varargin{i}))];
0052   end
0053 end
0054 
0055 if ~isempty (pl)
0056   pl = combine(pl);
0057 end
0058 
0059 %% go through analysis objects
0060 for j=1:length(ao_set)
0061   a = ao_set(j);
0062 
0063   [h, sum_data] = single_operation(a.data, 'sum', pl);
0064 
0065   %% Add the history from the ao object to the history
0066   h = set(h, 'inhists', [a.hist]);
0067 
0068   %% Set the var_name to the history
0069   if (j <= nargin)
0070     if (isempty (inputname(j)))
0071       h = set(h, 'invars', cellstr('no var_name'));
0072     else
0073       h = set(h, 'invars', cellstr(inputname(j)));
0074     end
0075   else
0076     h = set(h, 'invars', cellstr('no var_name'));
0077   end
0078 
0079   % convert to cdata type
0080   sum_x    = [];
0081   sum_y    = [];
0082 
0083   do_xdata = find(pl, 'xdata');
0084   do_ydata = find(pl, 'ydata');
0085 
0086   %% Is no axis entry in the parameter list
0087   %% then set the default axis = xdata
0088   if isempty(do_xdata) && isempty(do_ydata)
0089     do_ydata = 'yes';
0090   end
0091 
0092   %% Get the operation result. It is stored in the individual axis
0093   pl_get_axis = plist([param('xdata', do_xdata) param('ydata', do_ydata)]);
0094   [sum_x, sum_y] = get_xy_axis(sum_data, pl_get_axis);
0095 
0096   sum_cdata = cdata([sum_x sum_y]);
0097   sum_cdata = set (sum_cdata, 'name', sum_data.name);
0098   sum_cdata = set (sum_cdata, 'xunits', sum_data.xunits);
0099   sum_cdata = set (sum_cdata, 'yunits', sum_data.yunits);
0100 
0101   %% create a new analysis objects
0102   new_ao = a;
0103   new_ao = ao  (sum_cdata, h);
0104   new_ao = set (new_ao, 'name', sprintf('sum(%s)',a.name) );
0105 
0106   ao_out = [ao_out new_ao];
0107 
0108 end
0109 
0110 % END

Generated on Fri 08-Jun-2007 16:09:11 by m2html © 2003