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 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.5 2007/06/22 10:19:57 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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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 % 0013 % OUTPUTS: b - output array of AOs 0014 % 0015 % PARAMETERS: '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 % REMARK: Matrix cdata objects are not supported. 0023 % 0024 % VERSION: $Id: interp.m,v 1.5 2007/06/22 10:19:57 ingo Exp $ 0025 % 0026 % The following call returns a parameter list object that contains the 0027 % default parameter values: 0028 % 0029 % >> pl = interp(ao, 'Params') 0030 % 0031 % HISTORY: 05-06-07 M Hewitson 0032 % Creation 0033 % 0034 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0035 0036 ALGONAME = mfilename; 0037 VERSION = '$Id: interp.m,v 1.5 2007/06/22 10:19:57 ingo Exp $'; 0038 0039 0040 % Check if this is a call for parameters 0041 if nargin == 1 0042 in = char(varargin{1}); 0043 if strcmp(in, 'Params') 0044 varargout{1} = getDefaultPL(); 0045 return 0046 end 0047 end 0048 0049 % capture input variable names 0050 invars = {}; 0051 as = []; 0052 ps = []; 0053 for j=1:nargin 0054 invars = [invars cellstr(inputname(j))]; 0055 if isa(varargin{j}, 'ao') 0056 as = [as varargin{j}]; 0057 end 0058 if isa(varargin{j}, 'plist') 0059 ps = [ps varargin{j}]; 0060 end 0061 end 0062 0063 % check plist 0064 if isempty(ps) 0065 pl = getDefaultPL(); 0066 else 0067 pl = combine(ps, getDefaultPL); 0068 end 0069 0070 0071 % Get parameters 0072 vertices = find(pl, 'vertices'); 0073 method = find(pl, 'method'); 0074 0075 %----------------------- 0076 % Loop over input AOs 0077 bs = []; 0078 na = length(as); 0079 for j=1:na 0080 0081 a = as(j); 0082 0083 %---------------------------- 0084 % Get data 0085 [x,y] = getAOdata(a); 0086 0087 %---------------------------- 0088 % Interpolate this vector 0089 y = interp1(x,y,vertices, method, 'extrap'); 0090 0091 %---------------------------- 0092 % Make output AO/cdata 0093 si = size(vertices); 0094 if si(2) > si(1) && si(1) == 1 0095 vertices = vertices.'; 0096 end 0097 d = a.data; 0098 0099 d = set_xy_axis(d, vertices, y.'); 0100 0101 % if isa(d, 'tsdata') 0102 % d = set(d, 't', vertices); 0103 % d = set(d, 'x', y.'); 0104 % elseif isa(d, 'fsdata') 0105 % d = set(d, 'f', vertices); 0106 % d = set(d, 'xx', y.'); 0107 % elseif isa(d, 'cdata') 0108 % d = set(d, 'vals', y.'); 0109 % elseif isa(d, 'xydata') 0110 % d = set(d, 'x', vertices); 0111 % d = set(d, 'y', y.'); 0112 % else 0113 % error('### Unknown data type.') 0114 % end 0115 0116 d = set(d, 'name', sprintf('%s(%s)', method, d.name)); 0117 0118 h = history(ALGONAME, VERSION, pl, a.hist); 0119 h = set(h, 'invars', invars(j)); 0120 0121 % make output analysis object 0122 b = ao(d, h); 0123 0124 % set name 0125 if isempty(invars{j}) 0126 n = a.name; 0127 else 0128 n = invars{j}; 0129 end 0130 b = set(b, 'name', sprintf('%s(%s)', method, n)); 0131 0132 % add to outputs 0133 bs = [bs b]; 0134 0135 end 0136 0137 %--------------------- 0138 % Set outputs 0139 varargout{1} = bs; 0140 0141 %-------------------------------------------------------------------------- 0142 % Get default params 0143 function plo = getDefaultPL() 0144 0145 disp('* creating default plist...'); 0146 plo = plist(); 0147 plo = append(plo, param('vertices', [])); 0148 plo = append(plo, param('method', 'spline')); 0149 disp('* done.'); 0150 0151 0152 0153 0154 0155 % END