MEAN overloads the mean operator for Analysis objects. Compute the mean value. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: MEAN overloads the mean operator for Analysis objects. Compute the mean value. MEAN(ao) is the mean value of the elements in ao.data. CALL: ao_out = mean(ao_in); ao_out = mean(ao_in, dim); ao_out = mean(ao_in, pl); ao_out = mean(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 mean along the dimension dim tsdata fsdata xydata 'xdata' 't' 'f' 'x' compute the mean of the x-axis 'ydata' 'x' 'xx' 'y' compute the mean of the y-axis The following call returns a parameter list object that contains the default parameter values: >> pl = mean(ao, 'Params') HISTORY: 23-05-2007 Diepholz Creation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001 function ao_out = mean (varargin) 0002 % MEAN overloads the mean operator for Analysis objects. Compute the mean value. 0003 % 0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0005 % 0006 % DESCRIPTION: MEAN overloads the mean operator for Analysis objects. 0007 % Compute the mean value. 0008 % MEAN(ao) is the mean value of the elements in ao.data. 0009 % 0010 % CALL: ao_out = mean(ao_in); 0011 % ao_out = mean(ao_in, dim); 0012 % ao_out = mean(ao_in, pl); 0013 % ao_out = mean(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 mean along the 0021 % dimension dim 0022 % tsdata fsdata xydata 0023 % 'xdata' 't' 'f' 'x' compute the mean of the x-axis 0024 % 'ydata' 'x' 'xx' 'y' compute the mean of the y-axis 0025 % 0026 % The following call returns a parameter list object that contains the 0027 % default parameter values: 0028 % 0029 % >> pl = mean(ao, 'Params') 0030 % 0031 % HISTORY: 23-05-2007 Diepholz 0032 % Creation 0033 % 0034 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0035 0036 ALGONAME = mfilename; 0037 VERSION = '$Id: mean.m,v 1.8 2007/06/22 08:32:49 ingo Exp $'; 0038 ao_out = []; 0039 pl = plist(); 0040 option = ''; 0041 0042 %% Check if this is a call for parameters 0043 if nargin == 2 0044 if isa(varargin{1}, 'ao') && ischar(varargin{2}) 0045 in = char(varargin{2}); 0046 if strcmp(in, 'Params') 0047 ao_out = getDefaultPL(); 0048 return 0049 end 0050 end 0051 end 0052 0053 %% store the input ao's in the vector: ao_set 0054 ao_set = []; 0055 for i=1:nargin 0056 a = varargin{i}; 0057 if isa(a, 'ao') 0058 [m,n] = size(a); 0059 for i = 1:m 0060 for j = 1:n 0061 ao_set = [ao_set a(i,j)]; 0062 end 0063 end 0064 elseif isa(varargin{i}, 'plist') 0065 pl = [pl varargin{i}]; 0066 elseif isnumeric(varargin{i}) 0067 pl = [pl plist(param('dim', varargin{i}))]; 0068 end 0069 end 0070 0071 if ~isempty (pl) 0072 pl = combine(pl); 0073 end 0074 0075 %% go through analysis objects 0076 for j=1:length(ao_set) 0077 a = ao_set(j); 0078 0079 [h, mean_data] = single_operation(a.data, 'mean', pl); 0080 0081 %% Add the history from the ao object to the history 0082 h = set(h, 'inhists', [a.hist]); 0083 0084 %% Set the var_name to the history 0085 if (j <= nargin) 0086 if (isempty (inputname(j))) 0087 h = set(h, 'invars', cellstr('no var_name')); 0088 else 0089 h = set(h, 'invars', cellstr(inputname(j))); 0090 end 0091 else 0092 h = set(h, 'invars', cellstr('no var_name')); 0093 end 0094 0095 % convert to cdata type 0096 mean_x = []; 0097 mean_y = []; 0098 0099 do_xdata = find(pl, 'xdata'); 0100 do_ydata = find(pl, 'ydata'); 0101 0102 %% Is no axis entry in the parameter list 0103 %% then set the default axis = xdata 0104 if isempty(do_xdata) && isempty(do_ydata) 0105 do_ydata = 'yes'; 0106 end 0107 0108 %% Get the operation result. It is stored in the individual axis 0109 pl_get_axis = plist([param('xdata', do_xdata) param('ydata', do_ydata)]); 0110 [mean_x, mean_y] = get_xy_axis(mean_data, pl_get_axis); 0111 0112 mean_cdata = cdata([mean_x mean_y]); 0113 mean_cdata = set (mean_cdata, 'name', mean_data.name); 0114 mean_cdata = set (mean_cdata, 'xunits', mean_data.xunits); 0115 mean_cdata = set (mean_cdata, 'yunits', mean_data.yunits); 0116 0117 %% create a new analysis objects 0118 new_ao = a; 0119 new_ao = ao (mean_cdata, h); 0120 new_ao = set (new_ao, 'name', sprintf('mean(%s)',a.name) ); 0121 0122 ao_out = [ao_out new_ao]; 0123 0124 end 0125 0126 %% Get default params 0127 function pl_default = getDefaultPL() 0128 0129 disp('* creating default plist...'); 0130 pl_default = plist([param('dim', '') 0131 param('xdata', '') 0132 param('ydata', '')]); 0133 disp('* done.'); 0134 0135 % END