Home > classes > @fsdata > single_operation.m

single_operation

PURPOSE ^

SINGLE_OPERATION implements specified operator overload for fsdata objects.

SYNOPSIS ^

function varargout = single_operation (varargin)

DESCRIPTION ^

 SINGLE_OPERATION implements specified operator overload for fsdata objects.

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

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

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

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

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