


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
The following call returns a parameter list object that contains the
default parameter values:
>> pl = median(ao, 'Params')
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 % The following call returns a parameter list object that contains the 0027 % default parameter values: 0028 % 0029 % >> pl = median(ao, 'Params') 0030 % 0031 % HISTORY: 23-05-2007 Diepholz 0032 % Creation 0033 % 0034 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0035 0036 VERSION = '$Id: median.m,v 1.9 2007/11/26 14:48:13 ingo Exp $'; 0037 ao_out = []; 0038 0039 %% Check if this is a call for parameters 0040 if nargin == 2 0041 if isa(varargin{1}, 'ao') && ischar(varargin{2}) 0042 in = char(varargin{2}); 0043 if strcmp(in, 'Params') 0044 ao_out = getDefaultPL(); 0045 return 0046 elseif strcmp(in, 'Version') 0047 ao_out = VERSION; 0048 return 0049 end 0050 end 0051 end 0052 0053 %% Collect input ao's, plist's and ao variable names 0054 in_names = {}; 0055 ps = plist(); 0056 for ii = 1:nargin 0057 in_names{end+1} = inputname(ii); 0058 0059 if isnumeric(varargin{ii}) 0060 ps = [ps plist(param('dim', varargin{ii}))]; 0061 end 0062 end 0063 0064 [ao_set, pl, invars] = collect_inputs(varargin, in_names); 0065 0066 pl = combine(pl, ps); 0067 0068 %% go through analysis objects 0069 for j=1:numel(ao_set) 0070 a = ao_set(j); 0071 0072 [h, median_data] = single_operation(a.data, 'median', pl); 0073 0074 %% Add the history from the ao object to the history 0075 h = set(h, 'inhists', [a.hist]); 0076 0077 %% Set the var_name to the history 0078 h = set(h, 'invars', cellstr(invars{j})); 0079 0080 do_xdata = find(pl, 'xdata'); 0081 do_ydata = find(pl, 'ydata'); 0082 0083 %% Is no axis entry in the parameter list 0084 %% then set the default axis = xdata 0085 if isempty(do_xdata) && isempty(do_ydata) 0086 do_ydata = 'yes'; 0087 end 0088 0089 %% Get the operation result. It is stored in the individual axis 0090 pl_get_axis = plist([param('xdata', do_xdata) param('ydata', do_ydata)]); 0091 [median_x, median_y] = get_xy_values(median_data, pl_get_axis); 0092 0093 median_cdata = cdata([median_x median_y]); 0094 median_cdata = set (median_cdata, 'name', median_data.name); 0095 median_cdata = set (median_cdata, 'xunits', median_data.xunits); 0096 median_cdata = set (median_cdata, 'yunits', median_data.yunits); 0097 0098 %% create a new analysis objects 0099 new_ao = a; 0100 new_ao = ao (median_cdata, h); 0101 new_ao = setnh(new_ao, 'name', sprintf('median(%s)',invars{j}) ); 0102 0103 ao_out = [ao_out new_ao]; 0104 0105 end 0106 0107 % Reshape the ouput to the same size of the input 0108 ao_out = reshape(ao_out, size(ao_set)); 0109 0110 0111 %% Get default params 0112 function pl_default = getDefaultPL() 0113 0114 pl_default = plist([param('dim', '') 0115 param('xdata', '') 0116 param('ydata', '')]); 0117 0118 % END