LINCOM %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: LINCOM CALL: b = lincom(a1,a2,a3,...,pl) b = lincom(a1,a2,a3,...,aN) If no parameter list is specified, one of the analysis objects should contain a cdata type with the coefficients inside. INPUTS: aN - a list of analysis objects of the same type pl - a parameter list OUTPUTS: b - output analysis object PARAMETERS: 'coeffs' - vector of coefficients, same length as number of input AOs M-FILE INFO: Get information about this methods by calling >> ao.getInfo('lincom') Get information about a specified set-plist by calling: >> ao.getInfo('lincom', 'None') VERSION: $Id: lincom.m,v 1.9 2008/09/05 11:05:29 ingo Exp $ HISTORY: 14-02-07 M Hewitson Creation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001 % LINCOM 0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0003 % 0004 % DESCRIPTION: LINCOM 0005 % 0006 % CALL: b = lincom(a1,a2,a3,...,pl) 0007 % b = lincom(a1,a2,a3,...,aN) 0008 % 0009 % If no parameter list is specified, one of the analysis objects 0010 % should contain a cdata type with the coefficients inside. 0011 % 0012 % INPUTS: aN - a list of analysis objects of the same type 0013 % pl - a parameter list 0014 % 0015 % OUTPUTS: b - output analysis object 0016 % 0017 % PARAMETERS: 'coeffs' - vector of coefficients, same length as number of input AOs 0018 % 0019 % M-FILE INFO: Get information about this methods by calling 0020 % >> ao.getInfo('lincom') 0021 % 0022 % Get information about a specified set-plist by calling: 0023 % >> ao.getInfo('lincom', 'None') 0024 % 0025 % VERSION: $Id: lincom.m,v 1.9 2008/09/05 11:05:29 ingo Exp $ 0026 % 0027 % HISTORY: 14-02-07 M Hewitson 0028 % Creation 0029 % 0030 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0031 0032 function varargout = lincom(varargin) 0033 0034 %%% Check if this is a call for parameters 0035 if utils.helper.isinfocall(varargin{:}) 0036 varargout{1} = getInfo(varargin{3}); 0037 return 0038 end 0039 0040 import utils.const.* 0041 utils.helper.msg(msg.MNAME, 'running %s/%s', mfilename('class'), mfilename); 0042 0043 %%% Collect input variable names 0044 in_names = cell(size(varargin)); 0045 for ii = 1:nargin,in_names{ii} = inputname(ii);end 0046 0047 %%% Collect all AOs 0048 [as, ao_invars, rest] = utils.helper.collect_objects(varargin(:), 'ao', in_names); 0049 [pli, pl_invars, rest] = utils.helper.collect_objects(rest, 'plist', in_names); 0050 0051 if nargout == 0 0052 error('### lincom cannot be used as a modifier. Please give an output variable.'); 0053 end 0054 0055 % Combine plists 0056 pl = combine(pli, getDefaultPlist); 0057 0058 % Collect coefficients from cdata, and AOs containing tsdata 0059 coeffs = []; 0060 ts = []; 0061 chist = []; 0062 for kk = 1:numel(as) 0063 if isa(as(kk).data, 'tsdata') 0064 ts = [ts as(kk)]; 0065 elseif isa(as(kk).data,'cdata') 0066 chist = as(kk).hist; 0067 coeffs = [coeffs as(kk).data.y]; 0068 else 0069 error('### lincom can only be used on tsdata AOs currently.'); 0070 end 0071 end 0072 0073 % If a plist is supplied and no cdata, use plist 0074 if ~isempty(pl) && isempty(coeffs) 0075 coeffs = find(pl, 'coeffs'); 0076 end 0077 0078 na = length(ts); 0079 nc = length(coeffs); 0080 if na ~= nc 0081 disp(sprintf('Num AOs input: %d', na)); 0082 disp(sprintf('Num Coeffs input: %d', nc)); 0083 error('### specify one coefficient per analysis object.'); 0084 end 0085 0086 % Compute the new units 0087 new_units = ts(1).data.yunits; 0088 for kk = 2:numel(ts); 0089 new_units = new_units + ts(kk).data.yunits; 0090 end 0091 0092 % Make linear combination and collect name string 0093 nstr = ''; 0094 y = zeros(size(ts(1).data.y)); 0095 for j=1:nc 0096 nstr = [nstr num2str(coeffs(j)) '*' ao_invars{j} ' + ']; 0097 y = y + coeffs(j).*ts(j).data.y; 0098 end 0099 nstr = deblank(nstr(1:end-2)); 0100 0101 % create new ao 0102 b = ao; 0103 b.data = copy(ts(1).data,1); 0104 b.data.setY(y); 0105 0106 %%% Set Name 0107 b.setName(nstr, 'internal'); 0108 0109 %%% Set new Units 0110 b.setYunits(new_units, 'internal'); 0111 0112 %%% Add History 0113 b.addHistory(getInfo('None'), pl, ao_invars, [ts.hist chist]); 0114 0115 %%% Reshape the ouput to the same size of the input 0116 varargout{1} = b; 0117 end 0118 0119 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0120 % Local Functions % 0121 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0122 0123 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0124 % 0125 % FUNCTION: getInfo 0126 % 0127 % DESCRIPTION: Get Info Object 0128 % 0129 % HISTORY: 11-07-07 M Hewitson 0130 % Creation. 0131 % 0132 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0133 0134 function ii = getInfo(varargin) 0135 if nargin == 1 && strcmpi(varargin{1}, 'None') 0136 sets = {}; 0137 pl = []; 0138 else 0139 sets = {'Default'}; 0140 pl = getDefaultPlist; 0141 end 0142 % Build info object 0143 ii = minfo(mfilename, 'ao', '', utils.const.categories.sigproc, '$Id: lincom.m,v 1.9 2008/09/05 11:05:29 ingo Exp $', sets, pl); 0144 end 0145 0146 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0147 % 0148 % FUNCTION: getDefaultPlist 0149 % 0150 % DESCRIPTION: Get Default Plist 0151 % 0152 % HISTORY: 11-07-07 M Hewitson 0153 % Creation. 0154 % 0155 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0156 0157 function plo = getDefaultPlist() 0158 plo = plist(); 0159 end 0160 0161