0001 function varargout = single_operation (varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039 VERSION = '$Id: single_operation.m,v 1.13 2007/11/26 18:07:51 ingo Exp $';
0040
0041
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
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
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
0076 pl_default = getDefaultPL();
0077
0078
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
0092
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
0103 if isnumeric(option) || islogical(option)
0104 option = num2str(option);
0105 end
0106
0107
0108 do_xdata = 'x';
0109 do_ydata = 'y';
0110
0111
0112 if isnumeric(dim) || islogical (dim)
0113 dim = num2str(dim);
0114 end
0115
0116
0117
0118
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
0124 if (nargout >= 2)
0125
0126
0127
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
0138
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
0145
0146 try
0147
0148
0149
0150 if ~isempty(option)
0151 cmd_line = sprintf('%s = %s(y,%s);',y_new, op, option);
0152 eval (cmd_line);
0153
0154
0155
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
0161
0162 elseif ~isempty(dim)
0163 cmd_line = sprintf('%s = %s(y,%s);',y_new, op, dim);
0164 eval (cmd_line);
0165
0166
0167
0168 elseif ~isempty(weight_vector)
0169 cmd_line = sprintf('%s = %s(y,weight_vector);',y_new, op);
0170 eval (cmd_line);
0171
0172
0173
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
0187
0188 for i = 1:nargout-1
0189
0190
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
0195 eval (sprintf('varargout{i+1} = data_out%d;',i))
0196
0197 end
0198
0199
0200 h = history(op, VERSION);
0201
0202 varargout{1} = h;
0203
0204 else
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