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

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