MEDIAN overloads the median operator for Analysis objects. Compute the median value. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: MEDIAN overloads the median operator for Analysis objects. Compute the median value. MEDIAN(ao) is the median value of the elements in ao.data. CALL: ao_out = median(ao_in); ao_out = median(ao_in, dim); ao_out = median(ao_in, pl); ao_out = median(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 median along the dimension dim tsdata fsdata xydata 'xdata' 't' 'f' 'x' compute the median of the x-axis 'ydata' 'x' 'xx' 'y' compute the median of the y-axis HISTORY: 23-05-2007 Diepholz Creation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001 function ao_out = median (varargin) 0002 % MEDIAN overloads the median operator for Analysis objects. Compute the median value. 0003 % 0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0005 % 0006 % DESCRIPTION: MEDIAN overloads the median operator for Analysis objects. 0007 % Compute the median value. 0008 % MEDIAN(ao) is the median value of the elements in ao.data. 0009 % 0010 % CALL: ao_out = median(ao_in); 0011 % ao_out = median(ao_in, dim); 0012 % ao_out = median(ao_in, pl); 0013 % ao_out = median(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 median along the 0021 % dimension dim 0022 % tsdata fsdata xydata 0023 % 'xdata' 't' 'f' 'x' compute the median of the x-axis 0024 % 'ydata' 'x' 'xx' 'y' compute the median of the y-axis 0025 % 0026 % HISTORY: 23-05-2007 Diepholz 0027 % Creation 0028 % 0029 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0030 0031 ALGONAME = mfilename; 0032 VERSION = '$Id: median.html,v 1.1 2007/06/08 14:15:02 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, median_data] = single_operation(a.data, 'median', 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 median_x = []; 0081 median_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 [median_x, median_y] = get_xy_axis(median_data, pl_get_axis); 0095 0096 median_cdata = cdata([median_x median_y]); 0097 median_cdata = set (median_cdata, 'name', median_data.name); 0098 median_cdata = set (median_cdata, 'xunits', median_data.xunits); 0099 median_cdata = set (median_cdata, 'yunits', median_data.yunits); 0100 0101 %% create a new analysis objects 0102 new_ao = a; 0103 new_ao = ao (median_cdata, h); 0104 new_ao = set (new_ao, 'name', sprintf('median(%s)',a.name) ); 0105 0106 ao_out = [ao_out new_ao]; 0107 0108 end 0109 0110 % END