home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l460 / 2.ddi / POLYFUN.DI$ / INTERP2.M < prev    next >
Encoding:
Text File  |  1993-03-07  |  2.4 KB  |  71 lines

  1. function [zi,w] = interp2(x,y,z,xi,yi,method)
  2. %INTERP2 2-D data interpolation (table lookup).
  3. %    ZI = INTERP2(X,Y,Z,XI,YI) returns matrix ZI containing elements
  4. %    corresponding to the elements of XI and YI and determined by 
  5. %    interpolation within the 2-D function described by matrices X, Y, 
  6. %    and Z.  Out of range values are returned as NaN.
  7. %
  8. %    X can be a row vector, in which case the elements are assumed to 
  9. %    apply to the columns of Z. Similarly, Y can be a column vector
  10. %    and its elements are assumed to apply across the rows of Z.
  11. %
  12. %    Interpolation is the same operation as "table lookup".  Described in
  13. %    "table lookup" terms, the "table" is TAB = [NaN,Y; X,Z] and INTERP2 
  14. %    "looks-up" the elements of XI in X, YI in Y, and, based upon their 
  15. %    location, returns values ZI interpolated within the elements of Z.
  16. %
  17. %    By default, INTERP2 uses bilinear interpolation.
  18. %    ZI = INTERP2(X,Y,Z,XI,YI,'method') specifies alternate methods.
  19. %    Available methods are:
  20. %
  21. %      'linear' - bilinear interpolation
  22. %      'cubic'  - bicubic interpolation
  23. %
  24. %    All the interpolation methods require that X and Y be monotonic.
  25. %    The 'cubic' method also requires that the points in X and Y be 
  26. %    equally-spaced.
  27. %
  28. %    See also INTERP1, GRIDDATA.
  29.  
  30. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  31.  
  32. error(nargchk(3,6,nargin));
  33.  
  34. % Trap call to old interp2, but call interp1 with 'spline' instead
  35. if nargin == 3 
  36.     disp('This usage of interp2(x,y,xi) is obsolete and will be eliminated')
  37.     disp('in future versions. Please use interp1(x,y,xi,''spline'') instead.')
  38. end
  39. if nargin == 4
  40.     disp('This usage of interp2(x,y,xi,w) is obsolete and will be eliminated')
  41.     disp('in future versions. Please use interp1(x,y,xi,''spline'') instead.')
  42. end
  43. if nargin==3, zi = interp1(x,y,z,'spline'); return, end
  44. if nargin==4, zi = interp1(x,y,z,'spline'); return, end
  45.   
  46. % Check the arguments.
  47. if nargin<6,
  48.   method = 'linear';
  49. end
  50.  
  51. if ~isstr(method),
  52.   error('METHOD must be one of the strings: ''linear'' or ''cubic''.');
  53. end
  54.  
  55. [msg,x,y,z,xi,yi] = xyzchk(x,y,z,xi,yi); % Check arguments
  56.  
  57. if ~isempty(msg), error(msg); end
  58.  
  59. if method(1)=='l' | method(1)=='b', % Linear interpolation. Bilinear ('b')
  60.   zi = interp4(x,y,z,xi,yi);        % option included for backward compatibility
  61.  
  62. elseif method(1)=='c', % bicubic interpolation
  63.   zi = interp5(x,y,z,xi,yi);
  64.  
  65. else
  66.   error([method,' is an invalid method.']);
  67.  
  68. end
  69.  
  70.  
  71.