FOO is the standard function template for class methods. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: FOO is the standard function template for class methods. CALL: foo(a) [a, b] = foo(a,pl) INPUTS: a - analysis object(s) pl - parameter list(s) ... OUTPUTS: a - ??? b - ??? PARAMETER LIST: <key> <value> <description> 'A' 'a' parameter description 'N' 5 parameter description DESCRIPTION 'User func. template' routine description The following call returns a parameter list object that contains the default parameter values: >> pl = foo(ao, 'Params') The following call returns a string that contains the routine CVS version: >> version = foo(ao, 'Version') The following call returns a string that contains the routine category: >> category = foo(ao, 'Category') VERSION: $Id: method_fcn_template.html,v 1.7 2008/03/31 10:27:44 hewitson Exp $ HISTORY: dd-mm-yyyy M Hewitson Creation SEE ALSO: ao/cos, ao/tan, ao/asin, acos, atan SEE: <a href="matlab: help ao/Contents;">HELP: All Analysis Object Functions:</a> <a href="matlab: helpwin ao/Contents;">DOC: All Analysis Object Functions:</a> %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001 function varargout = foo(varargin) 0002 % FOO is the standard function template for class methods. 0003 % 0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0005 % 0006 % DESCRIPTION: FOO is the standard function template for class methods. 0007 % 0008 % CALL: foo(a) 0009 % [a, b] = foo(a,pl) 0010 % 0011 % INPUTS: a - analysis object(s) 0012 % pl - parameter list(s) 0013 % ... 0014 % 0015 % OUTPUTS: a - ??? 0016 % b - ??? 0017 % 0018 % PARAMETER LIST: 0019 % <key> <value> <description> 0020 % 'A' 'a' parameter description 0021 % 'N' 5 parameter description 0022 % DESCRIPTION 'User func. template' routine description 0023 % 0024 % The following call returns a parameter list object that contains the 0025 % default parameter values: 0026 % 0027 % >> pl = foo(ao, 'Params') 0028 % 0029 % The following call returns a string that contains the routine CVS version: 0030 % 0031 % >> version = foo(ao, 'Version') 0032 % 0033 % The following call returns a string that contains the routine category: 0034 % 0035 % >> category = foo(ao, 'Category') 0036 % 0037 % VERSION: $Id: method_fcn_template.html,v 1.7 2008/03/31 10:27:44 hewitson Exp $ 0038 % 0039 % HISTORY: dd-mm-yyyy M Hewitson 0040 % Creation 0041 % 0042 % SEE ALSO: ao/cos, ao/tan, ao/asin, acos, atan 0043 % 0044 % SEE: <a href="matlab: help ao/Contents;">HELP: All Analysis Object Functions:</a> 0045 % <a href="matlab: helpwin ao/Contents;">DOC: All Analysis Object Functions:</a> 0046 % 0047 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0048 0049 ALGONAME = mfilename; 0050 VERSION = '$Id: method_fcn_template.html,v 1.7 2008/03/31 10:27:44 hewitson Exp $'; 0051 CATEGORY = 'Signal Processing'; 0052 0053 0054 %% Check if this is a call for parameters, the CVS version string 0055 % or the method category 0056 0057 % Version for standard usage 0058 if nargin == 2 && ... 0059 isa(varargin{1}, 'ao') && ... 0060 ischar(varargin{2}) 0061 in = char(varargin{2}); 0062 if strcmpi(in, 'Params') 0063 varargout{1} = getDefaultPL(); 0064 return 0065 elseif strcmpi(in, 'Version') 0066 varargout{1} = VERSION; 0067 return 0068 elseif strcmp(in, 'Category') 0069 varargout{1} = CATEGORY; 0070 return 0071 end 0072 end 0073 0074 0075 % Version for usage with sets of parameters, such as the class creators 0076 % if (nargin == 2 || nargin == 3) && ... 0077 % isa(varargin{1}, 'ao') && ... 0078 % ischar(varargin{2}) 0079 % in = char(varargin{2}); 0080 % if strcmp(in, 'Params') 0081 % if nargin == 2 0082 % varargout{1} = getDefaultPL(); 0083 % else 0084 % varargout{1} = getDefaultPL(varargin{3}); 0085 % end 0086 % return 0087 % elseif strcmp(in, 'Version') 0088 % varargout{1} = VERSION; 0089 % return 0090 % elseif strcmp(in, 'Category') 0091 % varargout{1} = CATEGORY; 0092 % return 0093 % end 0094 % end 0095 0096 0097 %% Collect input ao's, plist's and ao variable names 0098 in_names = {}; 0099 for ii = 1:nargin 0100 in_names{end+1} = inputname(ii); 0101 end 0102 0103 [as, pl, invars] = collect_inputs(varargin, in_names); 0104 0105 % produce one parameter list 0106 if isa(pl, 'plist') 0107 pl = combine(pl, getDefaultPL()); 0108 else 0109 pl = getDefaultPL(); 0110 end 0111 0112 0113 %% Get parameters 0114 A = find(pl, 'A'); 0115 X = find(pl, 'X'); 0116 0117 0118 %% Initialize outputs 0119 bs = []; 0120 0121 0122 %% Go through analysis objects 0123 for j=1:numel(as) 0124 a = as(j); 0125 0126 % get data 0127 [x,y] = get_xy_values(a.data); 0128 0129 % Do some analysis 0130 y = 2*A * (y + X); 0131 x = 1:length(x); 0132 0133 %%-------- Build output AOs 0134 0135 % make a new xydata object, for example 0136 xy = xydata(x, y); 0137 xy = set(xy, 'name', sprintf('foo(%s)', a.data.name)); 0138 xy = set(xy, 'xunits', a.data.xunits); 0139 xy = set(xy, 'yunits', 'Blah'); 0140 0141 % make a new history object 0142 h = history(ALGONAME, VERSION, pl, a.hist); 0143 h = set(h, 'invars', invars); 0144 0145 % make output analysis object 0146 b = ao(xy, h); 0147 0148 % name, mfilename, description for this object 0149 b = setnh(b, 'name', sprintf('foo(%s)', invars{j}),... 0150 'description', find(pl,'description')); 0151 0152 bs = [bs b]; 0153 0154 end 0155 0156 0157 %% Reshape the ouput to the same size of the input 0158 varargout{1} = reshape(bs, size(as)); 0159 0160 0161 %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0162 % 0163 % FUNCTION: getDefaultPL 0164 % 0165 % DESCRIPTION: Get default params, version for standard usage 0166 % 0167 % HISTORY: dd-mm-yyyy M Hewitson 0168 % Creation 0169 % 0170 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0171 function plo = getDefaultPL() 0172 0173 plo = plist('A', 10, ... 0174 'X', [1], ... 0175 'DESCRIPTION','LTPDA Method Template'); 0176 0177 0178 0179 0180 %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0181 % 0182 % FUNCTION: getDefaultPL 0183 % 0184 % DESCRIPTION: Get default params, version for usage with sets 0185 % 0186 % HISTORY: dd-mm-yyyy M Hewitson 0187 % Creation 0188 % 0189 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0190 % function out = getDefaultPL(varargin) 0191 % 0192 % % list of available parameter sets 0193 % sets = {'From XML file', 'From ASCII file', 'Function', 'Values',... 0194 % 'Time-series Function', 'From Window', 'Waveform'}; 0195 % 0196 % if nargin == 0 0197 % out = sets; 0198 % return 0199 % end 0200 % 0201 % set = varargin{1}; 0202 % 0203 % switch set 0204 % case 'From XML file' 0205 % out = plist('filename', 'foo.xml'); 0206 % case 'From ASCII file' 0207 % out = plist('filename', 'foo.txt',... 0208 % 'type', 'tsdata',... 0209 % 'columns', [1 2],... 0210 % 'num_columns', 10,... 0211 % 'comment_char', '%'); 0212 % case 'Function' 0213 % out = plist('fcn', 'randn(100,1)'); 0214 % case 'Values' 0215 % out = plist('vals', [1 2 3]); 0216 % case 'Time-series Function' 0217 % out = plist('tsfcn', 'randn(size(t))', 'fs', 10, 'nsecs', 100); 0218 % case 'From Window' 0219 % out = plist('win', specwin('Hanning', 100)); 0220 % case 'Waveform' 0221 % out = plist('waveform', 'sine wave',... 0222 % 'f', 1.23,... 0223 % 'phi', 0,... 0224 % 'fs', 10,... 0225 % 'nsecs', 10); 0226 % otherwise 0227 % out = plist(); 0228 % end 0229 0230 % END