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