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.9 2007/07/11 16:01:24 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     disp('sdf')
0093   end
0094 
0095   %% Convert the <double> option into a char
0096   if isnumeric(option) || islogical(option)
0097     option = num2str(option);
0098   end
0099 
0100   %% Compute always the vals data
0101   do_xdata = 'vals';
0102   do_ydata = 'vals';
0103 
0104   %% Convert the dim into a char
0105   if isnumeric(dim) || islogical (dim)
0106     dim = num2str(dim);
0107   end
0108 
0109   %% The operation can only compute with a 'option' or with a 'dimension'.
0110   %% e.g. operation(ao, option)
0111   %%      operation(ao, dim)
0112   if ~isempty(option) && ~isempty(dim)
0113     warning ('### xydata/single_operation: The param list contain a ''option'' and a ''dim''. It is computed %s(ao,option).', op);
0114   end
0115 
0116 %% %% Ensure that the called function have at least two output variables
0117   if (nargout >= 2)
0118 
0119 %%  %% Create the output string for the eval command
0120     %% e.g.: vals_new = '[ vals_new1 vals_new2 ]'
0121     vals_new = '[';
0122     for i = 1:nargout-1
0123       new_var_name = genvarname (sprintf('vals_new%d',i));
0124       eval ([new_var_name '= 0;']);
0125 
0126       vals_new = strcat(vals_new, sprintf (' vals_new%d',i));
0127     end
0128     vals_new = strcat (vals_new, ' ]');
0129 
0130 %%  %% Create the output variables
0131     %% e.g.: data_out1 = data;
0132     for i = 1:nargout-1
0133       new_var_name = genvarname (sprintf('data_out%d',i));
0134       eval ([new_var_name '= data;']);
0135     end
0136 
0137 %%  Execute the command
0138 
0139     try
0140 
0141       %% Execute with a option or a dimension
0142       %% >> operation(vals,'option');
0143       if ~isempty(option)
0144         cmd_line = sprintf('%s = %s(vals,%s);',vals_new, op, option);
0145         eval (cmd_line);
0146 
0147       %% Execute with a weight vector and dimension
0148       %% >> operation(vals,W,dim);
0149       elseif ~isempty(dim) && ~isempty(weight_vector)
0150         cmd_line = sprintf('%s = %s(vals,weight_vector,%s);',vals_new, op, dim);
0151         eval (cmd_line);
0152 
0153       %% Execute with a option or a dimension
0154       %% >> operation(vals,dim);
0155       elseif ~isempty(dim)
0156         cmd_line = sprintf('%s = %s(vals,%s);',vals_new, op, dim);
0157         eval (cmd_line);
0158 
0159       %% Execute with a weight vector
0160       %% >> operation(vals,W);
0161       elseif ~isempty(weight_vector)
0162         cmd_line = sprintf('%s = %s(vals,weight_vector);',vals_new, op);
0163         eval (cmd_line);
0164 
0165       %% Execute without parameter or option
0166       %% >> operation(vals)
0167       else
0168         cmd_line = sprintf('%s = %s(vals);',vals_new, op);
0169         eval (cmd_line);
0170       end
0171 
0172     catch
0173       l_error = lasterror;
0174       disp(sprintf('\n\n%s', l_error.message));
0175       error('### cdata/single_operation: Can not command:\n###    %s\n### Have a look to the param list', cmd_line);
0176     end
0177 
0178 
0179 %%  %% The result from eval is in vals_new1, ...
0180     %% Create a cdata object from this results and write it into the output
0181     for i = 1:nargout-1
0182 
0183       %% Create cdata
0184       eval (sprintf('data_out%d.vals = vals_new%d;',i,i));
0185       eval (sprintf('data_out%d.name = ''%s(%s)'';',i,op,data.name));
0186 
0187       %% Write to output
0188       eval (sprintf('varargout{i+1} = data_out%d;',i))
0189 
0190     end
0191 
0192     %% Create a new history object
0193     h = history(op, VERSION);
0194 
0195     varargout{1} = h;
0196 
0197   else % (nargout < 2)
0198     error ('### cdata/single_operation: This function need at least two output variables.');
0199   end
0200 
0201 else
0202   error ('### cdata/single_operation: This function need three input variables.')
0203 end

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