Home > classes > @cdata > single_operation.m

single_operation

PURPOSE ^

SINGLE_OPERATION implements specified operator overload for cdata objects.

SYNOPSIS ^

function varargout = single_operation (varargin)

DESCRIPTION ^

 SINGLE_OPERATION implements specified operator overload for cdata objects.

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

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

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

 varargin format: 1:   [cdata]
                  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>

 >> 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 cdata objects.
0003 %
0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 % DESCRIPTION: SINGLE_OPERATION implements specified operator overload
0007 %              for cdata objects.
0008 %              ATTENTION: Should only be called from a analysis function.
0009 %
0010 % CALL: [h, data_out] = single_operation(a.data, 'svd', pl)
0011 %
0012 % varargin format: 1:   [cdata]
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 %
0027 % >> operation(data,'option')          option <char>
0028 % >> operation(data,option)            option <double>
0029 % >> operation(data,W,dim)
0030 % >> operation(data,dim)
0031 % >> operation(data,W)
0032 % >> operation(data)
0033 %
0034 % HISTORY: 07-05-2007 Diepholz
0035 %             Creation.
0036 %
0037 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0038 
0039 VERSION  = '$Id: single_operation.m,v 1.13 2007/11/26 18:07:51 ingo Exp $';
0040 
0041 % Check if this is a call for parameters
0042 if nargin == 2
0043   if isa(varargin{1}, 'cdata') && ischar(varargin{2})
0044     in = char(varargin{2});
0045     if strcmp(in, 'Params')
0046       varargout{1} = getDefaultPL();
0047       return
0048     elseif strcmp(in, 'Version')
0049       varargout{1} = VERSION;
0050       return
0051     end
0052   end
0053 end
0054 
0055 % Only the call from an analysis object is allowed.
0056 if (nargin == 3)
0057 
0058   data = varargin {1};
0059   op   = varargin {2};
0060   pl   = varargin {3};
0061   a    = varargin {end};
0062   y    = data.y;
0063 
0064 %% Verify input variables and set default parameter
0065   if ~isa(data, 'cdata')
0066     error ('### cdata/single_operation: The first input must be a cdata.');
0067   end
0068   if ~ischar(op)
0069     error ('### cdata/single_operation: The second input must be a string.');
0070   end
0071   if ~isa(plist, 'plist')
0072     error ('### cdata/single_operation: The third input must be a plist.');
0073   end
0074 
0075   %% Set default parameter list
0076   pl_default = getDefaultPL();
0077 
0078   %% Combine the handover param-list and the default param-list
0079   if ~isempty(pl)
0080     pl = combine(pl);
0081   else
0082     pl = combine(pl_default);
0083   end
0084 
0085   option        = find(pl, 'option');
0086   dim           = find(pl, 'dim');
0087   weight_vector = find(pl, 'W');
0088   do_xdata      = find(pl, 'xdata');
0089   do_ydata      = find(pl, 'ydata');
0090 
0091   %% Check the <char> option if it begins and ends  with a quote '
0092   %% If not then add the quote.
0093   if ischar(option) && ~isempty(option)
0094     if ~strcmp(option(1), '''')
0095       option = ['''' option];
0096     end
0097     if ~strcmp(option(end), '''')
0098       option = [option ''''];
0099     end
0100   end
0101 
0102   %% Convert the <double> option into a char
0103   if isnumeric(option) || islogical(option)
0104     option = num2str(option);
0105   end
0106 
0107   %% Compute always the y data
0108   do_xdata = 'x';
0109   do_ydata = 'y';
0110 
0111   %% Convert the dim into a char
0112   if isnumeric(dim) || islogical (dim)
0113     dim = num2str(dim);
0114   end
0115 
0116   %% The operation can only compute with a 'option' or with a 'dimension'.
0117   %% e.g. operation(ao, option)
0118   %%      operation(ao, dim)
0119   if ~isempty(option) && ~isempty(dim)
0120     warning ('### xydata/single_operation: The param list contain a ''option'' and a ''dim''. It is computed %s(ao,option).', op);
0121   end
0122 
0123 %% %% Ensure that the called function have at least two output variables
0124   if (nargout >= 2)
0125 
0126 %%  %% Create the output string for the eval command
0127     %% e.g.: y_new = '[ y_new1 y_new2 ]'
0128     y_new = '[';
0129     for i = 1:nargout-1
0130       new_var_name = genvarname (sprintf('y_new%d',i));
0131       eval ([new_var_name '= 0;']);
0132 
0133       y_new = strcat(y_new, sprintf (' y_new%d',i));
0134     end
0135     y_new = strcat (y_new, ' ]');
0136 
0137 %%  %% Create the output variables
0138     %% e.g.: data_out1 = data;
0139     for i = 1:nargout-1
0140       new_var_name = genvarname (sprintf('data_out%d',i));
0141       eval ([new_var_name '= data;']);
0142     end
0143 
0144 %%  Execute the command
0145 
0146     try
0147 
0148       %% Execute with a option or a dimension
0149       %% >> operation(y,'option');
0150       if ~isempty(option)
0151         cmd_line = sprintf('%s = %s(y,%s);',y_new, op, option);
0152         eval (cmd_line);
0153 
0154       %% Execute with a weight vector and dimension
0155       %% >> operation(y,W,dim);
0156       elseif ~isempty(dim) && ~isempty(weight_vector)
0157         cmd_line = sprintf('%s = %s(y,weight_vector,%s);',y_new, op, dim);
0158         eval (cmd_line);
0159 
0160       %% Execute with a option or a dimension
0161       %% >> operation(y,dim);
0162       elseif ~isempty(dim)
0163         cmd_line = sprintf('%s = %s(y,%s);',y_new, op, dim);
0164         eval (cmd_line);
0165 
0166       %% Execute with a weight vector
0167       %% >> operation(y,W);
0168       elseif ~isempty(weight_vector)
0169         cmd_line = sprintf('%s = %s(y,weight_vector);',y_new, op);
0170         eval (cmd_line);
0171 
0172       %% Execute without parameter or option
0173       %% >> operation(y)
0174       else
0175         cmd_line = sprintf('%s = %s(y);',y_new, op);
0176         eval (cmd_line);
0177       end
0178 
0179     catch
0180       l_error = lasterror;
0181       disp(sprintf('\n\n%s', l_error.message));
0182       error('### cdata/single_operation: Can not command:\n###    %s\n### Have a look to the param list', cmd_line);
0183     end
0184 
0185 
0186 %%  %% The result from eval is in y_new1, ...
0187     %% Create a cdata object from this results and write it into the output
0188     for i = 1:nargout-1
0189 
0190       %% Create cdata
0191       eval (sprintf('data_out%d.y = y_new%d;',i,i));
0192       eval (sprintf('data_out%d.name = ''%s(%s)'';',i,op,data.name));
0193 
0194       %% Write to output
0195       eval (sprintf('varargout{i+1} = data_out%d;',i))
0196 
0197     end
0198 
0199     %% Create a new history object
0200     h = history(op, VERSION);
0201 
0202     varargout{1} = h;
0203 
0204   else % (nargout < 2)
0205     error ('### cdata/single_operation: This function need at least two output variables.');
0206   end
0207 
0208 else
0209   error ('### cdata/single_operation: This function need three input variables.')
0210 end
0211 
0212 
0213 function pl_default = getDefaultPL()
0214 
0215   pl_default = plist('option', '',  ...
0216                      'dim',    '',  ...
0217                      'W',      [],  ...
0218                      'xdata',  'x', ...
0219                      'ydata',  'y');
0220

Generated on Tue 22-Jan-2008 10:39:13 by m2html © 2003