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

  1. function [xi,yi,zi] = griddata(x,y,z,xi,yi,method)
  2. %GRIDDATA Data gridding.
  3. %    ZI = GRIDDATA(X,Y,Z,XI,YI) returns matrix ZI containing elements
  4. %    corresponding to the elements of matrices XI and YI and determined by
  5. %    interpolation within the 2-D function described by the (usually)
  6. %    nonuniformly-spaced vectors (X,Y,Z).
  7. %
  8. %    XI can be a row vector, in which case it specifies a matrix with
  9. %    constant columns. Similarly, YI can be a column vector and it 
  10. %    specifies a matrix with constant rows. 
  11. %
  12. %    [XI,YI,ZI] = GRIDDATA(X,Y,Z,XI,YI) returns the XI and YI formed
  13. %    this way, which are the same as the matrices returned by MESHGRID.
  14. %
  15. %    GRIDDATA uses an inverse distance method.
  16. %
  17. %    See also INTERP2, INTERP1.
  18.  
  19. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  20.  
  21. error(nargchk(5,5,nargin)) % Ignore method for now.
  22.  
  23. [msg,x,y,z,xi,yi] = xyzchk(x,y,z,xi,yi);
  24.  
  25. if length(msg)>0, error(msg); end
  26. xy = x(:) + y(:)*sqrt(-1);
  27.  
  28. % Determine weights for interpolation
  29. d = xy * ones(1,length(xy));
  30. d = abs(d - d.');
  31. mask = find(d == 0);
  32. d(mask) = ones(length(mask),1);
  33. g = (d.^2) .* (log(d)-1);   % Green's function.
  34. g(mask) = zeros(length(mask),1); % Value of Green's function at zero
  35. weights = g \ z(:);
  36.  
  37. [m,n] = size(xi);
  38. zi = zeros(m,n);
  39. jay = sqrt(-1);
  40. xy = xy.';
  41.  
  42. % Evaluate at requested points (xi,yi).  Loop to save memory.
  43. for i=1:m
  44.   for j=1:n
  45.     d = abs(xi(i,j)+jay*yi(i,j) - xy);
  46.     mask = find(d == 0);
  47.     if length(mask)>0, d(mask) = ones(length(mask),1); end
  48.     g = (d.^2) .* (log(d)-1);   % Green's function.
  49.     % Value of Green's function at zero
  50.     if length(mask)>0, g(mask) = zeros(length(mask),1); end
  51.     zi(i,j) = g * weights;
  52.   end
  53. end
  54.  
  55.  
  56. if nargout<=1,
  57.   xi = zi;
  58. end
  59.  
  60.  
  61.  
  62.  
  63.  
  64.