Home > classes > @ao > interp.m

interp

PURPOSE ^

INTERP interpolate the values in the input AO(s) at new values specified

SYNOPSIS ^

function varargout = interp(varargin)

DESCRIPTION ^

 INTERP interpolate the values in the input AO(s) at new values specified
 by the input parameter list.
 
 Usage: b = interp(a, pl)
 
 Inputs:
   a  - input array of AOs
 
 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
 
 
 * Matrix cdata objects are not supported.
 
 M Hewitson 05-06-07

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

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

Generated on Fri 08-Jun-2007 16:09:11 by m2html © 2003