Home > classes > @ao > interp.m

interp

PURPOSE ^

INTERP interpolate the values in the input AO(s) at new values specified by the input parameter list.

SYNOPSIS ^

function varargout = interp(varargin)

DESCRIPTION ^

 INTERP interpolate the values in the input AO(s) at new values specified by the input parameter list.

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

 DESCRIPTION: INTERP interpolate the values in the input AO(s) at new values
              specified by the input parameter list.

 CALL:        b = interp(a, pl)

 INPUTS:      a  - input array of AOs
              pl - parameter list with the keys 'vertices' and 'method'

 OUTPUTS:     b  - output array of AOs

 PARAMETERS:  'vertices'     - new set of vertices to interpolate on.
              'method'       - one of:
                   'nearest' - nearest neighbour
                   'linear'  - linear interpolation
                   'spline'  - spline interpolation
                   'cubic'   - shape-preserving piecewise cubic interpolation

 REMARK:      Matrix cdata objects are not supported.

 VERSION:     $Id: interp.m,v 1.8 2007/10/25 13:37:17 ingo Exp $

 The following call returns a parameter list object that contains the
 default parameter values:

 >> pl = interp(ao, 'Params')

 HISTORY: 05-06-07 M Hewitson
             Creation

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function varargout = interp(varargin)
0002 % INTERP interpolate the values in the input AO(s) at new values specified by the input parameter list.
0003 %
0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 % DESCRIPTION: INTERP interpolate the values in the input AO(s) at new values
0007 %              specified by the input parameter list.
0008 %
0009 % CALL:        b = interp(a, pl)
0010 %
0011 % INPUTS:      a  - input array of AOs
0012 %              pl - parameter list with the keys 'vertices' and 'method'
0013 %
0014 % OUTPUTS:     b  - output array of AOs
0015 %
0016 % PARAMETERS:  'vertices'     - new set of vertices to interpolate on.
0017 %              'method'       - one of:
0018 %                   'nearest' - nearest neighbour
0019 %                   'linear'  - linear interpolation
0020 %                   'spline'  - spline interpolation
0021 %                   'cubic'   - shape-preserving piecewise cubic interpolation
0022 %
0023 % REMARK:      Matrix cdata objects are not supported.
0024 %
0025 % VERSION:     $Id: interp.m,v 1.8 2007/10/25 13:37:17 ingo Exp $
0026 %
0027 % The following call returns a parameter list object that contains the
0028 % default parameter values:
0029 %
0030 % >> pl = interp(ao, 'Params')
0031 %
0032 % HISTORY: 05-06-07 M Hewitson
0033 %             Creation
0034 %
0035 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0036 
0037 ALGONAME = mfilename;
0038 VERSION  = '$Id: interp.m,v 1.8 2007/10/25 13:37:17 ingo Exp $';
0039 
0040 
0041 % Check if this is a call for parameters
0042 if nargin == 2
0043   in = char(varargin{2});
0044   if strcmp(in, 'Params')
0045     varargout{1} = getDefaultPL();
0046     return
0047   elseif strcmp(in, 'Version')
0048     varargout{1} = VERSION;
0049     return
0050   end
0051 end
0052 
0053 % capture input variable names
0054 invars = {};
0055 as     = [];
0056 ps     = [];
0057 for j=1:nargin
0058   invars = [invars cellstr(inputname(j))];
0059   if isa(varargin{j}, 'ao')
0060     as = [as varargin{j}];
0061   end
0062   if isa(varargin{j}, 'plist')
0063     ps = [ps varargin{j}];
0064   end
0065 end
0066 
0067 % check plist
0068 if isempty(ps)
0069   pl = getDefaultPL();
0070 else
0071   pl = combine(ps, getDefaultPL);
0072 end
0073 
0074 
0075 % Get parameters
0076 vertices = find(pl, 'vertices');
0077 method  = find(pl, 'method');
0078 
0079 %-----------------------
0080 % Loop over input AOs
0081 bs = [];
0082 for j=1:numel(as)
0083 
0084   a = as(j);
0085 
0086   %----------------------------
0087   % Get data
0088   [x,y] = get_xy_values(a.data);
0089 
0090   %----------------------------
0091   % Interpolate this vector
0092   if ~isempty(x)
0093     % for tsdata, fsdata and xydata objects
0094     y = interp1(x,y,vertices, method, 'extrap');
0095   else
0096     % for cdata object
0097     y = interp1(y,vertices, method, 'extrap');
0098   end
0099 
0100   %----------------------------
0101   % Make output AO/cdata
0102   d = a.data;
0103 
0104   d = set_xy_axis(d, vertices, y.');
0105 
0106   d = set(d, 'name', sprintf('%s(%s)', method, d.name));
0107 
0108   if j <= length(invars)
0109     invars_name = invars(j);
0110   end
0111 
0112   h = history(ALGONAME, VERSION, pl, a.hist);
0113   h = set(h, 'invars', invars_name);
0114 
0115   % make output analysis object
0116   b = ao(d, h);
0117 
0118   % set name
0119   if j > length(invars)
0120     n = a.name;
0121   else
0122     n = invars{j};
0123   end
0124   b = set(b, 'name', sprintf('%s(%s)', method, n));
0125 
0126   % add to outputs
0127   bs = [bs b];
0128 
0129 end
0130 
0131 % Reshape the ouput to the same size of the input
0132 bs = reshape(bs, size(as));
0133 
0134 % Set outputs
0135 varargout{1} = bs;
0136 
0137 %--------------------------------------------------------------------------
0138 % Get default params
0139 function plo = getDefaultPL()
0140 
0141 plo = plist();
0142 plo = append(plo, param('vertices', []));
0143 plo = append(plo, param('method', 'spline'));
0144 
0145 
0146 
0147 
0148 
0149 % END

Generated on Fri 02-Nov-2007 19:39:27 by m2html © 2003