gridResample3D.m 1.4 KB

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