Home > m > etc > method_fcn_template.m

method_fcn_template

PURPOSE ^

FOO is the standard function template for class methods.

SYNOPSIS ^

function varargout = foo(varargin)

DESCRIPTION ^

 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  - ???

 PARAMETERS:  (Add these parameters to the default parameter list)
   A: - parameter description 
   X: - parameter description
   DESCRIPTION: - user defined routine description       

 VERSION:     $Id: method_fcn_template.m,v 1.3 2008/02/15 16:25:38 mauro Exp $

 HISTORY:     dd-mm-yyyy M Hewitson
                 Creation

 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')

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

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

Generated on Tue 26-Feb-2008 10:52:52 by m2html © 2003