0001 function [a1,a2,do] = aooperate(varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010 ALGONAME = mfilename;
0011 VERSION = '$Id: aooperate.m,v 1.18 2008/02/13 18:05:44 hewitson Exp $';
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 op = varargin{end};
0022 varargin = varargin{1:end-1};
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036 nargin = length(varargin);
0037
0038 as = [];
0039 for j=1:nargin
0040 a = varargin{j};
0041 if isa(a, 'ao')
0042 if any(size(a) > 1)
0043 error('### The operation works only with single analysis objects. Do not use vector or matrices of analysis objects.')
0044 end
0045 as = [as a];
0046 elseif isnumeric(a)
0047
0048 as = [as ao(a)];
0049 elseif isa(a, 'plist')
0050 val = find(a, 'Value');
0051 if ~isempty(val)
0052 as = [as ao(val)];
0053 end
0054 else
0055 error('### AO/plus inputs must be either numeric, plist(''Value''), or AO.');
0056 end
0057 end
0058
0059 if length(as) > 2
0060 warning('!!! I only work with the first two input AOs. Ignoring all others.');
0061 warning('!!! Perhaps you have input an AO array?');
0062 end
0063
0064
0065 a1 = as(1);
0066 a2 = as(2);
0067 clear as;
0068 d1 = a1.data;
0069 d2 = a2.data;
0070
0071
0072
0073 if (isa(d1, 'fsdata') && isa(d2, 'tsdata')) || (isa(d1, 'tsdata') && isa(d2, 'fsdata'))
0074 error('### can''t add time-series data to frequency-series data.');
0075 end
0076 if (isa(d1, 'xydata') && isa(d2, 'tsdata')) || (isa(d1, 'tsdata') && isa(d2, 'xydata'))
0077 error('### can''t add XY data to time-series data.');
0078 end
0079 if (isa(d1, 'xydata') && isa(d2, 'fsdata')) || (isa(d1, 'fsdata') && isa(d2, 'xydata'))
0080 error('### can''t add XY data to frequency-series data.');
0081 end
0082
0083
0084 [x1, y1] = get_xy_values(a1.data);
0085 [x2, y2] = get_xy_values(a2.data);
0086 ny1 = length(y1);
0087 ny2 = length(y2);
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099 if isa(d1, 'cdata') && ~isa(d2, 'cdata')
0100 if ny1 > 1 && ny1~=ny2
0101 error('###1 cdata type must be same length as other AO, or single valued.');
0102 end
0103 elseif isa(d2, 'cdata') && ~isa(d1, 'cdata')
0104 if ny2 > 1 && ny1~=ny2
0105 error('###2 cdata type must be same length as other AO, or single valued.');
0106 end
0107 end
0108
0109 if ny1~=ny2
0110 if ny1~=1 && ny2~=1
0111 error('### data vectors must be the same length or one should be single valued.');
0112 end
0113 end
0114
0115
0116 if isa(d1, 'fsdata') && isa(d2, 'fsdata')
0117 if ~strcmp(d1.xunits, d2.xunits)
0118 error('### xunits must be the same for same type of AOs.');
0119 end
0120
0121 if d1.x ~= d2.x
0122 error('### frequency vectors are not the same.');
0123 end
0124 end
0125 if isa(d1, 'tsdata') && isa(d2, 'tsdata')
0126 if ~strcmp(d1.xunits, d2.xunits)
0127 error('### xunits must be the same for same type of AOs.');
0128 end
0129 end
0130 if isa(d1, 'xydata') && isa(d2, 'xydata')
0131 if ~strcmp(d1.xunits, d2.xunits)
0132 error('### xunits must be the same for same type of AOs.');
0133 end
0134 end
0135
0136
0137
0138 eval(sprintf('y = y1%sy2;', op));
0139
0140
0141
0142 if isa(d1, 'fsdata') || isa(d2, 'fsdata')
0143
0144
0145
0146 if isa(d1, 'fsdata')
0147 d = d1;
0148 else
0149 d = d2;
0150 end
0151
0152 do = fsdata(d.x, y, d.fs);
0153 do = set(do, 'name', sprintf('(%s) %s (%s)', d1.name, op, d2.name));
0154 do = set(do, 'xunits', d.xunits);
0155 do = set(do, 'yunits', d.yunits);
0156 do = set(do, 'enbw', d.enbw);
0157
0158 elseif isa(d1, 'tsdata') || isa(d2, 'tsdata')
0159
0160
0161 if isa(d1, 'tsdata')
0162 d = d1;
0163 else
0164 d = d2;
0165 end
0166
0167 do = d;
0168 do = set(do, 'y', y);
0169 do = set(do, 'name', sprintf('(%s) %s (%s)', d1.name, op, d2.name));
0170
0171 elseif isa(d1, 'xydata') || isa(d2, 'xydata')
0172
0173
0174 if isa(d1, 'xydata')
0175 d = d1;
0176 else
0177 d = d2;
0178 end
0179
0180 do = xydata(d.x, y);
0181 do = set(do, 'name', sprintf('(%s) %s (%s)', d1.name, op, d2.name));
0182 do = set(do, 'xunits', d.xunits);
0183 do = set(do, 'yunits', d.yunits);
0184
0185 elseif isa(d1, 'cdata') || isa(d2, 'cdata')
0186
0187
0188
0189 if isa(d1, 'cdata')
0190 d = d1;
0191 else
0192 d = d2;
0193 end
0194
0195 do = cdata(y);
0196 do = set(do, 'name', sprintf('(%s) %s (%s)', d1.name, op, d2.name));
0197 do = set(do, 'xunits', d.xunits);
0198 do = set(do, 'yunits', d.yunits);
0199
0200 else
0201 error('### unknown data type - 2');
0202 end
0203
0204
0205