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:

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

Generated on Fri 02-Nov-2007 19:39:27 by m2html © 2003