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:

SUBFUNCTIONS ^

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 VERSION  = '$Id: single_operation.html,v 1.14 2008/03/31 10:27:43 hewitson Exp $';
0045 CATEGORY = 'Internal';
0046 
0047 % Check if this is a call for parameters
0048 if nargin == 2
0049   if isa(varargin{1}, 'xydata') && ischar(varargin{2})
0050     in = char(varargin{2});
0051     if strcmp(in, 'Params')
0052       varargout{1} = getDefaultPL();
0053       return
0054     elseif strcmp(in, 'Version')
0055       varargout{1} = VERSION;
0056       return
0057     elseif strcmp(in, 'Category')
0058       varargout{1} = CATEGORY;
0059       return
0060     end
0061   end
0062 end
0063 
0064 % Only the call from an analysis object is allowed.
0065 if (nargin == 3)
0066 
0067   data = varargin {1};
0068   op   = varargin {2};
0069   pl   = varargin {3};
0070   a    = varargin {end};
0071   x    = data.x;
0072   y    = data.y;
0073 
0074 %% Verify input variables and set default parameter
0075   if ~isa(data, 'xydata')
0076     error ('### xydata/single_operation: The first input must be a xydata.');
0077   end
0078   if ~ischar(op)
0079     error ('### xydata/single_operation: The second input must be a string.');
0080   end
0081   if ~isa(plist, 'plist')
0082     error ('### xydata/single_operation: The third input must be a plist.');
0083   end
0084 
0085   %% Set default parameter list
0086   pl_default = getDefaultPL();
0087 
0088   %% Combine the handover param-list and the default param-list
0089   if ~isempty(pl)
0090     pl = combine(pl);
0091   else
0092     pl = combine(pl_default);
0093   end
0094 
0095   option        = find(pl, 'option');
0096   dim           = find(pl, 'dim');
0097   weight_vector = find(pl, 'W');
0098   do_xdata      = find(pl, 'xdata');
0099   do_ydata      = find(pl, 'ydata');
0100 
0101   %% Check the <char> option if it begins and ends  with a quote '
0102   %% If not then add the quote.
0103   if ischar(option) && ~isempty(option)
0104     if ~strcmp(option(1), '''')
0105       option = ['''' option];
0106     end
0107     if ~strcmp(option(end), '''')
0108       option = [option ''''];
0109     end
0110   end
0111 
0112   %% Convert the <double> option into a char
0113   if isnumeric(option) || islogical(option)
0114     option = num2str(option);
0115   end
0116 
0117   %% Convert the dim into a char
0118   if isnumeric(dim) || islogical(dim)
0119     dim = num2str(dim);
0120   end
0121 
0122   %% The operation can only compute with a 'option' or with a 'dimension'.
0123   %% e.g. operation(ao, 'option')
0124   %%      operation(ao, dim)
0125   if ~isempty(option) && ~isempty(dim)
0126     warning ('### xydata/single_operation: The param list contain a ''option'' and a ''dim''. It is computed %s(ao,option).', op);
0127   end
0128 
0129   %%
0130   if isempty(do_xdata) && isempty(do_ydata)
0131     do_ydata = 'y';
0132   end
0133 
0134 %% %% Ensure that the called function have at least two output variables
0135   if (nargout >= 2)
0136 
0137 %%  %% xdata:
0138     %% Create the output string for the eval command
0139     %% e.g.: x_new = '[ x_new1 x_new2 ]'
0140     x_new = '[';
0141     for i = 1:nargout-1
0142       new_var_name = genvarname (sprintf('x_new%d',i));
0143       eval ([new_var_name '= 0;']);
0144 
0145       x_new = strcat(x_new, sprintf (' x_new%d',i));
0146     end
0147     x_new = strcat (x_new, ' ]');
0148 
0149     %% ydata:
0150     %% Create the output string for the eval command
0151     %% e.g.: y_new = '[ y_new1 y_new2 ]'
0152     y_new = '[';
0153     for i = 1:nargout-1
0154       new_var_name = genvarname (sprintf('y_new%d',i));
0155       eval ([new_var_name '= 0;']);
0156 
0157       y_new = strcat(y_new, sprintf (' y_new%d',i));
0158     end
0159     y_new = strcat (y_new, ' ]');
0160 
0161 %%  %% Create the output variables
0162     %% e.g.: data_out1 = data;
0163     for i = 1:nargout-1
0164       new_var_name = genvarname (sprintf('data_out%d',i));
0165       eval ([new_var_name '= data;']);
0166     end
0167 
0168 %%  Execute the command for the xdata
0169     if ~isempty(do_xdata)
0170 
0171       try
0172         %% Execute with a option
0173         %% >> operation(x,'option');
0174         if ~isempty(option)
0175           cmd_line = sprintf('%s = %s(x,%s);',x_new, op, option);
0176           eval (cmd_line);
0177 
0178         %% Execute with a weight vector and dimension
0179         %% >> operation(x,W,dim);
0180         elseif ~isempty(dim) && ~isempty(weight_vector)
0181           cmd_line = sprintf('%s = %s(x,weight_vector,%s);',x_new, op, dim);
0182           eval (cmd_line);
0183 
0184         %% Execute with a dimension
0185         %% >> operation(x,dim);
0186         elseif ~isempty(dim)
0187           cmd_line = sprintf('%s = %s(x,%s);',x_new, op, dim);
0188           eval (cmd_line);
0189 
0190         %% Execute with a weight vector
0191         %% >> operation(x,W);
0192         elseif ~isempty(weight_vector)
0193           cmd_line = sprintf('%s = %s(x,weight_vector);',x_new, op);
0194           eval (cmd_line);
0195 
0196         %% Execute without parameter or option
0197         %% >> operation(x)
0198         else
0199           cmd_line = sprintf('%s = %s(x);',x_new, op);
0200           eval (cmd_line);
0201         end
0202 
0203       catch
0204         l_error = lasterror;
0205         disp(sprintf('\n\n%s', l_error.message));
0206         error('### cdata/single_operation: Can not command:\n###    %s\n### Have a look to the param list', cmd_line);
0207       end
0208 
0209     end
0210 
0211 %%  Execute the command for the ydata
0212     if ~isempty(do_ydata)
0213 
0214       try
0215         %% Execute with a option or a dimension
0216         %% >> operation(y,'option');
0217         if ~isempty(option)
0218           cmd_line = sprintf('%s = %s(y,%s);',y_new, op, option);
0219           eval (cmd_line);
0220 
0221         %% Execute with a weight vector and dimension
0222         %% >> operation(y,W,dim);
0223         elseif ~isempty(dim) && ~isempty(weight_vector)
0224           cmd_line = sprintf('%s = %s(y,weight_vector,%s);',y_new, op, dim);
0225           eval (cmd_line);
0226 
0227         %% Execute with a option or a dimension
0228         %% >> operation(y,dim);
0229         elseif ~isempty(dim)
0230           cmd_line = sprintf('%s = %s(y,%s);',y_new, op, dim);
0231           eval (cmd_line);
0232 
0233         %% Execute with a weight vector
0234         %% >> operation(y,W);
0235         elseif ~isempty(weight_vector)
0236           cmd_line = sprintf('%s = %s(y,weight_vector);',y_new, op);
0237           eval (cmd_line);
0238 
0239         %% Execute without parameter or option
0240         %% >> operation(y)
0241         else
0242           cmd_line = sprintf('%s = %s(y);',y_new, op);
0243           eval (cmd_line);
0244         end
0245 
0246       catch
0247         l_error = lasterror;
0248         disp(sprintf('\n\n%s', l_error.message));
0249         error('### cdata/single_operation: Can not command:\n###    %s\n### Have a look to the param list', cmd_line);
0250       end
0251 
0252     end
0253 
0254 %%  %% The result from eval is in x_new1, y_new1, ...
0255     %% Create a xydata object from this results and write it into the output
0256     for i = 1:nargout-1
0257 
0258       %% Create xydata
0259       if ~isempty(do_xdata)
0260         eval (sprintf('data_out%d.x = x_new%d;',i,i));
0261         eval (sprintf('data_out%d.name = ''%s(%s)'';',i,op,data.name));
0262         eval (sprintf('data_out%d.xunits = ''%s(%s)'';',i,op,data.xunits));
0263       end
0264       if ~isempty(do_ydata)
0265         eval (sprintf('data_out%d.y = y_new%d;',i,i));
0266         eval (sprintf('data_out%d.name = ''%s(%s)'';',i,op,data.name));
0267         eval (sprintf('data_out%d.yunits = ''%s(%s)'';',i,op,data.yunits));
0268       end
0269 
0270       %% Write to output
0271       eval (sprintf('varargout{i+1} = data_out%d;',i))
0272 
0273     end
0274 
0275     %% Create a new history object
0276     h = history(op, VERSION);
0277 
0278     varargout{1} = h;
0279 
0280   else % (nargout < 2)
0281     error ('### xydata/single_operation: This function need at least two output variables.');
0282   end
0283 
0284 else
0285   error ('### xydata/single_operation: This function need three input variables.')
0286 end
0287 
0288 function pl_default = getDefaultPL()
0289 
0290   pl_default = plist('option', '',  ...
0291                      'dim',    '',  ...
0292                      'W',      [],  ...
0293                      'xdata',  '',  ...
0294                      'ydata',  'y');
0295

Generated on Mon 31-Mar-2008 12:20:24 by m2html © 2003