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 ALGONAME = mfilename;
0040 VERSION = '$Id: single_operation.m,v 1.10 2007/09/21 14:17:48 ingo Exp $';
0041
0042
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
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
0064 pl_default = plist([param('option', '')
0065 param('dim', '')
0066 param('W', [])
0067 param('xdata', 'vals')
0068 param('ydata', 'vals')]);
0069
0070
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
0084
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
0095 if isnumeric(option) || islogical(option)
0096 option = num2str(option);
0097 end
0098
0099
0100 do_xdata = 'vals';
0101 do_ydata = 'vals';
0102
0103
0104 if isnumeric(dim) || islogical (dim)
0105 dim = num2str(dim);
0106 end
0107
0108
0109
0110
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
0116 if (nargout >= 2)
0117
0118
0119
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
0130
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
0137
0138 try
0139
0140
0141
0142 if ~isempty(option)
0143 cmd_line = sprintf('%s = %s(vals,%s);',vals_new, op, option);
0144 eval (cmd_line);
0145
0146
0147
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
0153
0154 elseif ~isempty(dim)
0155 cmd_line = sprintf('%s = %s(vals,%s);',vals_new, op, dim);
0156 eval (cmd_line);
0157
0158
0159
0160 elseif ~isempty(weight_vector)
0161 cmd_line = sprintf('%s = %s(vals,weight_vector);',vals_new, op);
0162 eval (cmd_line);
0163
0164
0165
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
0179
0180 for i = 1:nargout-1
0181
0182
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
0187 eval (sprintf('varargout{i+1} = data_out%d;',i))
0188
0189 end
0190
0191
0192 h = history(op, VERSION);
0193
0194 varargout{1} = h;
0195
0196 else
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