Home > classes > @ao > mtimes.m

mtimes

PURPOSE ^

MTIMES overloads * operator for analysis objects.

SYNOPSIS ^

function b = mtimes(varargin)

DESCRIPTION ^

 MTIMES overloads * operator for analysis objects.
 
 This just does the same as times (*) for analysis objects.
 
 M Hewitson 05-02-07

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function b = mtimes(varargin)
0002 
0003 % MTIMES overloads * operator for analysis objects.
0004 %
0005 % This just does the same as times (*) for analysis objects.
0006 %
0007 % M Hewitson 05-02-07
0008 %
0009 
0010 % capture input variable names
0011 invars = {};
0012 for j=1:nargin
0013   iname = inputname(j);
0014   if isempty(iname) && isnumeric(varargin{j})
0015     iname = num2str(varargin{j});
0016   elseif isempty(iname) && ischar(varargin{j})
0017     iname = varargin{j};
0018   end    
0019   invars = [invars cellstr(iname)];
0020 end
0021 
0022 ALGONAME = mfilename;
0023 VERSION  = '$Id: mtimes.html,v 1.1 2007/06/08 14:15:02 hewitson Exp $';
0024 
0025 op = '*';
0026 
0027 [a1,a2,do] = aooperate(varargin, op);
0028 
0029 %--------- create output AO
0030 
0031 % make a new history object
0032 h = history(ALGONAME, VERSION, [], [a1.hist a2.hist]);
0033 h = set(h, 'invars', invars);
0034 
0035 % get names for output
0036 if isempty(char(invars{1}))
0037   n1 = a1.name;
0038 else
0039   n1 = char(invars{1});
0040 end
0041 if isempty(char(invars{2}))
0042   n2 = a2.name;
0043 else
0044   n2 = char(invars{2});
0045 end
0046 
0047 % make output analysis object
0048 % op = op(2:end);
0049 b = ao(do, h);
0050 b = set(b, 'name', sprintf('%s%s%s', n1, op, n2));
0051 
0052 end
0053 
0054 
0055 % % capture input variable names
0056 % invars = {};
0057 % for j=1:nargin
0058 %   invars = [invars cellstr(inputname(j))];
0059 % end
0060 %
0061 % ALGONAME = mfilename;
0062 % VERSION  = '$Id: mtimes.html,v 1.1 2007/06/08 14:15:02 hewitson Exp $';
0063 %
0064 % % We can force these to be two analysis objects here so
0065 % % that a=b*1 works.
0066 % %
0067 % % If b or c is a double of length 1, then we grow a new vector the same
0068 % % length as the data in the other. The other possibility is that one of the
0069 % % inputs is a vector the same length as the data vector in the other
0070 % % analysis object. If both are analysis objects, we deal with them below.
0071 %
0072 % if ~isa(b, 'ao')
0073 %   cd = c.data;
0074 %   if isa(cd, 'tsdata')
0075 %     x = tsdata(ones(size(cd.x))*b, cd.fs);
0076 %     x = set(x, 'xunits', cd.xunits, 'yunits', cd.yunits, 't0', cd.t0, 'name', num2str(b));
0077 %     bval = b;
0078 %     b = ao(x, history('const', '', plist(param('const', b))));
0079 %     b = set(b, 'name', num2str(bval));
0080 %   elseif isa(cd, 'fsdata')
0081 %     x = fsdata(ones(size(cd.x))*b, cd.fs);
0082 %     x = set(x, 'xunits', cd.xunits, 'yunits', cd.yunits, 't0', cd.t0, 'name', num2str(b));
0083 %     bval = b;
0084 %     b = ao(x, history('const', '', plist(param('const', b))));
0085 %     b = set(b, 'name', num2str(bval));
0086 %   else
0087 %     error('### analysis object has an unknown data type.');
0088 %   end
0089 %   clear cd;
0090 % end
0091 % if ~isa(c, 'ao')
0092 %   bd = b.data;
0093 %   if isa(bd, 'tsdata')
0094 %     x = tsdata(ones(size(bd.x))*c, bd.fs);
0095 %     x = set(x, 'xunits', bd.xunits, 'yunits', bd.yunits, 't0', bd.t0, 'name', num2str(c));
0096 %     cval = c;
0097 %     c = ao(x, history('const', '', plist(param('const', c))));
0098 %     c = set(c, 'name', num2str(cval));
0099 %   elseif isa(bd, 'fsdata')
0100 %     x = fsdata(ones(size(bd.xx))*c, bd.fs)
0101 %     x = set(x, 'xunits', bd.xunits, 'yunits', bd.yunits, 'enbw', bd.enbw, 'name', num2str(c));
0102 %     cval = c;
0103 %     c = ao(x, history('const', '', plist(param('const', c))));
0104 %     c = set(c, 'name', num2str(cval));
0105 %   else
0106 %     error('### analysis object has an unknown data type.');
0107 %   end
0108 %   clear bd;
0109 % end
0110 %
0111 % % Check both analysis objects have the same data type
0112 % d1 = get(b, 'data');
0113 % d2 = get(c, 'data');
0114 % d1info = whos('d1');
0115 % d2info = whos('d2');
0116 %
0117 % if d1info.class ~= d2info.class
0118 %   error('### two analysis objects have different data types. They can not be multiplied.');
0119 % end
0120 %
0121 % % Check both data types have the same Y units
0122 % if ~strcmp(d1.xunits, d2.xunits)
0123 %   warning('!!! multiplying two time/freq-series objects with different X units');
0124 %   xunits = [d1.xunits '/' d2.xunits];
0125 % else
0126 %   xunits = d1.xunits;
0127 % end
0128 %
0129 % % Check both data types have the same Y units
0130 % if ~strcmp(d1.yunits, d2.yunits)
0131 %   warning('!!! multiplying two time/freq-series objects with different Y units');
0132 %   yunits = [d1.yunits '*' d2.yunits];
0133 % else
0134 %   yunits = d1.yunits;
0135 % end
0136 %
0137 % % Which data type do we have
0138 % dtype = d1info.class;
0139 % switch dtype
0140 %   case 'tsdata'
0141 %     disp('* multiplying two tsdata objects');
0142 %
0143 %     % for now we ignore the time vectors
0144 %     if length(d1.x) ~= length(d2.x)
0145 %       error('### two data vectors are different lengths. They can not be multiplied.');
0146 %     end
0147 %     if length(d1.fs) ~= length(d2.fs)
0148 %       error('### two data vectors have different sample rates. They can not be multiplied.');
0149 %     end
0150 %
0151 %     % Check both data types have the same time origin
0152 %     if ~strcmp(d1.t0, d2.t0)
0153 %       warning('!!! multiplying two time-series objects with different time origins');
0154 %       t0 = [d1.t0 '/' d2.t0];
0155 %     else
0156 %       t0 = d1.t0;
0157 %     end
0158 %
0159 %     % make a new tsdata object
0160 %     ts = tsdata(d1.x.*d2.x, d1.fs);
0161 %     ts = set(ts, 'name', sprintf('(%s)*(%s)', d1.name, d2.name));
0162 %     ts = set(ts, 'xunits', xunits);
0163 %     ts = set(ts, 'yunits', yunits);
0164 %     ts = set(ts, 't0', t0);
0165 %
0166 %     % make a new history object
0167 %     h = history(ALGONAME, VERSION, [], [b.hist c.hist]);
0168 %     h = set(h, 'invars', invars);
0169 %
0170 %     % make output analysis object
0171 %     a = ao(ts, h);
0172 %     a = set(a, 'name', sprintf('%s*%s', invars{1}, invars{2}));
0173 %
0174 %   case 'fsdata'
0175 %     disp('* multiplying two fsdata objects');
0176 %
0177 %     % for now we ignore the freq vectors
0178 %     if length(d1.xx) ~= length(d2.xx)
0179 %       error('### two frequency vectors are different lengths. They can not be multiplied.');
0180 %     end
0181 %     if length(d1.fs) ~= length(d2.fs)
0182 %       error('### two original data vectors have different sample rates. They can not be multiplied.');
0183 %     end
0184 %     if d1.enbw ~= d2.enbw
0185 %       warning('!!! Equivalent noise bandwidth of the two frequency series does not match.');
0186 %     end
0187 %     % make a new tsdata object
0188 %     fs = fsdata(d1.f,d1.xx.*d2.xx, d1.fs);
0189 %     fs = set(fs, 'name', sprintf('(%s)*(%s)', d1.name, d2.name));
0190 %     fs = set(fs, 'xunits', xunits);
0191 %     fs = set(fs, 'yunits', yunits);
0192 %     fs = set(fs, 'enbw', d1.enbw);
0193 %
0194 %     % make a new history object
0195 %     h = history(ALGONAME, VERSION, [], [b.hist c.hist]);
0196 %     h = set(h, 'invars', invars);
0197 %
0198 %     % make output analysis object
0199 %     a = ao(fs, h);
0200 %     a = set(a, 'name', sprintf('%s*%s', invars{1}, invars{2}));
0201 %
0202 %   otherwise
0203 %     error('### unknown data type. They can not be addded.')
0204 % end
0205 
0206 % END

Generated on Fri 08-Jun-2007 16:09:11 by m2html © 2003