function fp = gridResample3D(varargin) %GRIDRESAMPLE3D 3-D interpolation % fp = gridResample3D(x,y,z,f,xp,yp,zp) resamples the values of the % function fp at points on a 3-D rectilinear grid specified by the vectors % xp, yp, zp, based on the original function, f, which has points % specified by the vectors x, y, z. The x, y, z vectors must be % monotonically increasing, but the vectors xp, yp, and zp do not. % fp = gridResample3D(...,mode) specifies an interpolation mode. The % 'mode' argument can be either 'linear' or 'nearest', which corresponds % to 3-D linear interpolation and nearest neighbor interpolation, % respectively. The default interpolation mode is 'linear'. % % For data defined on a simple Cartesian grid, this function is much % faster and more effective than interp3, which requires the user to input % a set of three 3D coordinate grids (one for each dimension), along with % the original data. This wastes time and memory. % % Ryan T Flynn, 6-27-07 % convert data to single format x = single(varargin{1}); y = single(varargin{2}); z = single(varargin{3}); f = single(varargin{4}); xp = single(varargin{5}); yp = single(varargin{6}); zp = single(varargin{7}); if length(varargin) == 8 if ischar(varargin{8}) mode = lower(varargin{8}); else error('Mode argument must be a character string.'); end else mode = 'linear'; end % do the interpolation fp = gridResample3Dc(x,y,z,f,xp,yp,zp,mode);