Home > classes > @xydata > single_operation.m

single_operation

PURPOSE ^

SINGLE_OPERATION implements specified operator overload for xydata objects.

SYNOPSIS ^

function varargout = single_operation (varargin)

DESCRIPTION ^

 SINGLE_OPERATION implements specified operator overload for xydata objects.

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

 DESCRIPTION: SINGLE_OPERATION implements specified operator overload
              for xydata objects.
              ATTENTION: Should only be called from a analysis function.

 CALL: [h, data_out] = single_operation(a.data, 'log', pl)

 varargin format: 1:   [xydata]
                  2:   ['operation']
                  3:   [plist]

 varargout format 1: [new_history]
                  2: [data_out1]
                  3: [data_out2]      optional
                  4: [data_out3]      optional
                         ...          optional

 With the plist values you can control the command line.
 Possible key values are: option   <double> or <char>
                          dim      <double> or <char>
                          W        <vector>
                          xdata    <char>
                          ydata    <char>
 With the keys xdata and ydata you can control which data are to compute.
 Attention the value of the key 'xdata' and 'ydata' must apply to the data class.
 The other values are controle the command line:

 >> operation(data,'option')         option <char>
 >> operation(data,option)           option <double>
 >> operation(data,W,dim)
 >> operation(data,dim)
 >> operation(data,W)
 >> operation(data)

 HISTORY: 07-05-2007 Diepholz
             Creation.

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function varargout = single_operation (varargin)
0002 % SINGLE_OPERATION implements specified operator overload for xydata objects.
0003 %
0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 % DESCRIPTION: SINGLE_OPERATION implements specified operator overload
0007 %              for xydata objects.
0008 %              ATTENTION: Should only be called from a analysis function.
0009 %
0010 % CALL: [h, data_out] = single_operation(a.data, 'log', pl)
0011 %
0012 % varargin format: 1:   [xydata]
0013 %                  2:   ['operation']
0014 %                  3:   [plist]
0015 %
0016 % varargout format 1: [new_history]
0017 %                  2: [data_out1]
0018 %                  3: [data_out2]      optional
0019 %                  4: [data_out3]      optional
0020 %                         ...          optional
0021 %
0022 % With the plist values you can control the command line.
0023 % Possible key values are: option   <double> or <char>
0024 %                          dim      <double> or <char>
0025 %                          W        <vector>
0026 %                          xdata    <char>
0027 %                          ydata    <char>
0028 % With the keys xdata and ydata you can control which data are to compute.
0029 % Attention the value of the key 'xdata' and 'ydata' must apply to the data class.
0030 % The other values are controle the command line:
0031 %
0032 % >> operation(data,'option')         option <char>
0033 % >> operation(data,option)           option <double>
0034 % >> operation(data,W,dim)
0035 % >> operation(data,dim)
0036 % >> operation(data,W)
0037 % >> operation(data)
0038 %
0039 % HISTORY: 07-05-2007 Diepholz
0040 %             Creation.
0041 %
0042 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0043 
0044 ALGONAME = mfilename;
0045 VERSION  = '$Id: single_operation.m,v 1.8 2007/07/11 16:01:24 ingo Exp $';
0046 
0047 % Only the call from an analysis object is allowed.
0048 if (nargin == 3)
0049 
0050   data = varargin {1};
0051   op   = varargin {2};
0052   pl   = varargin {3};
0053   a    = varargin {end};
0054   x    = data.x;
0055   y    = data.y;
0056 
0057 %% Verify input variables and set default parameter
0058   if ~isa(data, 'xydata')
0059     error ('### xydata/single_operation: The first input must be a xydata.');
0060   end
0061   if ~ischar(op)
0062     error ('### xydata/single_operation: The second input must be a string.');
0063   end
0064   if ~isa(plist, 'plist')
0065     error ('### xydata/single_operation: The third input must be a plist.');
0066   end
0067 
0068   %% Set default parameter list
0069   pl_default = plist([param('option', '')
0070                       param('dim',    '')
0071                       param('W',      [])
0072                       param('xdata',  '')
0073                       param('ydata',  'y')]);
0074 
0075   %% Combine the handover param-list and the default param-list
0076   if ~isempty(pl)
0077     pl = combine(pl);
0078   else
0079     pl = combine(pl_default);
0080   end
0081 
0082   option        = find(pl, 'option');
0083   dim           = find(pl, 'dim');
0084   weight_vector = find(pl, 'W');
0085   do_xdata      = find(pl, 'xdata');
0086   do_ydata      = find(pl, 'ydata');
0087 
0088   %% Validate xdata and ydata values
0089   if ~isempty(do_xdata) && (strcmp(do_xdata, 'x') == 0)
0090     error ('### xydata/single_operation: Invalid param for the key: ''xdata''. It must be a ''x''.')
0091   end
0092   if ~isempty(do_ydata) && (strcmp(do_ydata, 'y') == 0)
0093     error ('### xydata/single_operation: Invalid param for the key: ''ydata''. It must be a ''y''.')
0094   end
0095 
0096   %% Check the <char> option if it begins and ends  with a quote '
0097   %% If not then add the quote.
0098   if ischar(option) && ~isempty(option)
0099     if ~strcmp(option(1), '''')
0100       option = ['''' option];
0101     end
0102     if ~strcmp(option(end), '''')
0103       option = [option ''''];
0104     end
0105   end
0106 
0107   %% Convert the <double> option into a char
0108   if isnumeric(option) || islogical(option)
0109     option = num2str(option);
0110   end
0111 
0112   %% Convert the dim into a char
0113   if isnumeric(dim) || islogical(dim)
0114     dim = num2str(dim);
0115   end
0116 
0117   %% The operation can only compute with a 'option' or with a 'dimension'.
0118   %% e.g. operation(ao, 'option')
0119   %%      operation(ao, dim)
0120   if ~isempty(option) && ~isempty(dim)
0121     warning ('### xydata/single_operation: The param list contain a ''option'' and a ''dim''. It is computed %s(ao,option).', op);
0122   end
0123 
0124   %%
0125   if isempty(do_xdata) && isempty(do_ydata)
0126     do_ydata = 'y';
0127   end
0128 
0129 %% %% Ensure that the called function have at least two output variables
0130   if (nargout >= 2)
0131 
0132 %%  %% xdata:
0133     %% Create the output string for the eval command
0134     %% e.g.: x_new = '[ x_new1 x_new2 ]'
0135     x_new = '[';
0136     for i = 1:nargout-1
0137       new_var_name = genvarname (sprintf('x_new%d',i));
0138       eval ([new_var_name '= 0;']);
0139 
0140       x_new = strcat(x_new, sprintf (' x_new%d',i));
0141     end
0142     x_new = strcat (x_new, ' ]');
0143 
0144     %% ydata:
0145     %% Create the output string for the eval command
0146     %% e.g.: y_new = '[ y_new1 y_new2 ]'
0147     y_new = '[';
0148     for i = 1:nargout-1
0149       new_var_name = genvarname (sprintf('y_new%d',i));
0150       eval ([new_var_name '= 0;']);
0151 
0152       y_new = strcat(y_new, sprintf (' y_new%d',i));
0153     end
0154     y_new = strcat (y_new, ' ]');
0155 
0156 %%  %% Create the output variables
0157     %% e.g.: data_out1 = data;
0158     for i = 1:nargout-1
0159       new_var_name = genvarname (sprintf('data_out%d',i));
0160       eval ([new_var_name '= data;']);
0161     end
0162 
0163 %%  Execute the command for the xdata
0164     if ~isempty(do_xdata)
0165 
0166       try
0167         %% Execute with a option
0168         %% >> operation(x,'option');
0169         if ~isempty(option)
0170           cmd_line = sprintf('%s = %s(x,%s);',x_new, op, option);
0171           eval (cmd_line);
0172 
0173         %% Execute with a weight vector and dimension
0174         %% >> operation(x,W,dim);
0175         elseif ~isempty(dim) && ~isempty(weight_vector)
0176           cmd_line = sprintf('%s = %s(x,weight_vector,%s);',x_new, op, dim);
0177           eval (cmd_line);
0178 
0179         %% Execute with a dimension
0180         %% >> operation(x,dim);
0181         elseif ~isempty(dim)
0182           cmd_line = sprintf('%s = %s(x,%s);',x_new, op, dim);
0183           eval (cmd_line);
0184 
0185         %% Execute with a weight vector
0186         %% >> operation(x,W);
0187         elseif ~isempty(weight_vector)
0188           cmd_line = sprintf('%s = %s(x,weight_vector);',x_new, op);
0189           eval (cmd_line);
0190 
0191         %% Execute without parameter or option
0192         %% >> operation(x)
0193         else
0194           cmd_line = sprintf('%s = %s(x);',x_new, op);
0195           eval (cmd_line);
0196         end
0197 
0198       catch
0199         l_error = lasterror;
0200         disp(sprintf('\n\n%s', l_error.message));
0201         error('### cdata/single_operation: Can not command:\n###    %s\n### Have a look to the param list', cmd_line);
0202       end
0203 
0204     end
0205 
0206 %%  Execute the command for the ydata
0207     if ~isempty(do_ydata)
0208 
0209       try
0210         %% Execute with a option or a dimension
0211         %% >> operation(y,'option');
0212         if ~isempty(option)
0213           cmd_line = sprintf('%s = %s(y,%s);',y_new, op, option);
0214           eval (cmd_line);
0215 
0216         %% Execute with a weight vector and dimension
0217         %% >> operation(y,W,dim);
0218         elseif ~isempty(dim) && ~isempty(weight_vector)
0219           cmd_line = sprintf('%s = %s(y,weight_vector,%s);',y_new, op, dim);
0220           eval (cmd_line);
0221 
0222         %% Execute with a option or a dimension
0223         %% >> operation(y,dim);
0224         elseif ~isempty(dim)
0225           cmd_line = sprintf('%s = %s(y,%s);',y_new, op, dim);
0226           eval (cmd_line);
0227 
0228         %% Execute with a weight vector
0229         %% >> operation(y,W);
0230         elseif ~isempty(weight_vector)
0231           cmd_line = sprintf('%s = %s(y,weight_vector);',y_new, op);
0232           eval (cmd_line);
0233 
0234         %% Execute without parameter or option
0235         %% >> operation(y)
0236         else
0237           cmd_line = sprintf('%s = %s(y);',y_new, op);
0238           eval (cmd_line);
0239         end
0240 
0241       catch
0242         l_error = lasterror;
0243         disp(sprintf('\n\n%s', l_error.message));
0244         error('### cdata/single_operation: Can not command:\n###    %s\n### Have a look to the param list', cmd_line);
0245       end
0246 
0247     end
0248 
0249 %%  %% The result from eval is in x_new1, y_new1, ...
0250     %% Create a xydata object from this results and write it into the output
0251     for i = 1:nargout-1
0252 
0253       %% Create xydata
0254       if ~isempty(do_xdata)
0255         eval (sprintf('data_out%d.x = x_new%d;',i,i));
0256         eval (sprintf('data_out%d.name = ''%s(%s)'';',i,op,data.name));
0257         eval (sprintf('data_out%d.xunits = ''%s(%s)'';',i,op,data.xunits));
0258       end
0259       if ~isempty(do_ydata)
0260         eval (sprintf('data_out%d.y = y_new%d;',i,i));
0261         eval (sprintf('data_out%d.name = ''%s(%s)'';',i,op,data.name));
0262         eval (sprintf('data_out%d.yunits = ''%s(%s)'';',i,op,data.yunits));
0263       end
0264 
0265       %% Write to output
0266       eval (sprintf('varargout{i+1} = data_out%d;',i))
0267 
0268     end
0269 
0270     %% Create a new history object
0271     h = history(op, VERSION);
0272 
0273     varargout{1} = h;
0274 
0275   else % (nargout < 2)
0276     error ('### xydata/single_operation: This function need at least two output variables.');
0277   end
0278 
0279 else
0280   error ('### xydata/single_operation: This function need three input variables.')
0281 end

Generated on Mon 03-Sep-2007 12:12:34 by m2html © 2003