Home > classes > @ao > polyfit.m

polyfit

PURPOSE ^

POLYFIT overloads polyfit() function of MATLAB for Analysis Objects.

SYNOPSIS ^

function varargout = polyfit(varargin)

DESCRIPTION ^

 POLYFIT overloads polyfit() function of MATLAB for Analysis Objects.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: POLYFIT overloads polyfit() function of MATLAB for Analysis
              Objects.

 CALL:        b = polyfit(a, pl)

 PARAMETERS: 'N'      - degree of polynomial to fit
             'coeffs' - (optional) coefficients
                         formed e.g. by [p,s] = polyfit(x,y,N);

 M-FILE INFO: Get information about this methods by calling
              >> ao.getInfo('polyfit')

              Get information about a specified set-plist by calling:
              >> ao.getInfo('polyfit', 'None')

 VERSION:     $Id: polyfit.m,v 1.18 2008/09/05 11:05:29 ingo Exp $

 HISTORY:     05-06-07 M Hewitson
                 Creation

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 % POLYFIT overloads polyfit() function of MATLAB for Analysis Objects.
0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0003 %
0004 % DESCRIPTION: POLYFIT overloads polyfit() function of MATLAB for Analysis
0005 %              Objects.
0006 %
0007 % CALL:        b = polyfit(a, pl)
0008 %
0009 % PARAMETERS: 'N'      - degree of polynomial to fit
0010 %             'coeffs' - (optional) coefficients
0011 %                         formed e.g. by [p,s] = polyfit(x,y,N);
0012 %
0013 % M-FILE INFO: Get information about this methods by calling
0014 %              >> ao.getInfo('polyfit')
0015 %
0016 %              Get information about a specified set-plist by calling:
0017 %              >> ao.getInfo('polyfit', 'None')
0018 %
0019 % VERSION:     $Id: polyfit.m,v 1.18 2008/09/05 11:05:29 ingo Exp $
0020 %
0021 % HISTORY:     05-06-07 M Hewitson
0022 %                 Creation
0023 %
0024 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0025 
0026 function varargout = polyfit(varargin)
0027 
0028   % Check if this is a call for parameters
0029   if utils.helper.isinfocall(varargin{:})
0030     varargout{1} = getInfo(varargin{3});
0031     return
0032   end
0033 
0034   import utils.const.*
0035   utils.helper.msg(msg.MNAME, 'running %s/%s', mfilename('class'), mfilename);
0036   
0037   % Collect input variable names
0038   in_names = cell(size(varargin));
0039   for ii = 1:nargin,in_names{ii} = inputname(ii);end
0040 
0041   % Collect all AOs and plists
0042   [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names);
0043   pl              = utils.helper.collect_objects(varargin(:), 'plist', in_names);
0044 
0045   % Combine plists
0046   pl = combine(pl, getDefaultPlist);
0047 
0048   % Decide on a deep copy or a modify
0049   bs = copy(as, nargout);
0050 
0051   % Degree of polynomial to fit
0052   N      = find(pl, 'N');
0053   coeffs = find(pl, 'coeffs');
0054 
0055   %-----------------------
0056   % Loop over input AOs
0057   for j=1:numel(bs)
0058     if isa(bs(j).data, 'cdata')
0059       warning('!!! Can''t fit to cdata objects. Skipping AO %s', ao_invars{j});
0060       bs(j) = [];
0061     else
0062       % Get x values
0063       x = bs(j).data.getX;
0064       % Fit polynomial
0065       if ~isempty(N)
0066         [p,s] = polyfit(x, bs(j).data.getY, N);
0067       else
0068         p = coeffs;
0069         s = [];
0070       end
0071       % make new values from these coefficients
0072       y = polyval(p, bs(j).data.getX);
0073       % Set data
0074       bs(j).data.setXY(x, y);
0075       % Set output name
0076       bs(j).setName(sprintf('polyfit(%s)', ao_invars{j}), 'internal');
0077       % Set extra processing info
0078       bs(j).procinfo = plist('coeffs', p, 'S', s);
0079       % Add history
0080       bs(j).addHistory(getInfo, pl, ao_invars(j), bs(j).hist);
0081     end
0082   end
0083 
0084   % Set outputs
0085   if nargout > 0
0086     varargout{1} = bs;
0087   end
0088 end
0089 
0090 %--------------------------------------------------------------------------
0091 % Get Info Object
0092 %--------------------------------------------------------------------------
0093 function ii = getInfo(varargin)
0094   if nargin == 1 && strcmpi(varargin{1}, 'None')
0095     sets = {};
0096     pl   = [];
0097   else
0098     sets = {'Default'};
0099     pl   = getDefaultPlist;
0100   end
0101   % Build info object
0102   ii = minfo(mfilename, 'ao', '', utils.const.categories.sigproc, '$Id: polyfit.m,v 1.18 2008/09/05 11:05:29 ingo Exp $', sets, pl);
0103 end
0104 
0105 %--------------------------------------------------------------------------
0106 % Get Default Plist
0107 %--------------------------------------------------------------------------
0108 function pl_default = getDefaultPlist()
0109   pl_default = plist('N', 1, 'coeffs', []);
0110 end
0111 
0112 % END
0113

Generated on Mon 08-Sep-2008 13:18:47 by m2html © 2003