1 
function zi = griddata_fast(delau,z,method) 
2 
%GRIDDATA_FAST Data gridding and surface fitting. 
3 
% ZI = GRIDDATA_FAST(DEL,Z) 
4 
% 
5 
% See also GRIDDATA_PREPROCESS 
6 

7 
% Based on 
8 
% Clay M. Thompson 82195 
9 
% Copyright 19842001 The MathWorks, Inc. 
10 
% $Revision: 1.1 $ $Date: 2004/06/04 15:50:52 $ 
11 

12 
% $Header: $ 
13 
% $Name: $ 
14 

15 
error(nargchk(2,3,nargin)) 
16 

17 
if nargin<3, method = 'linear'; end 
18 
if ~isstr(method), 
19 
error('METHOD must be one of ''linear'',''cubic'',''nearest'', or ''v4''.'); 
20 
end 
21 

22 

23 
% Sort x and y so duplicate points can be averaged before passing to delaunay 
24 

25 
switch lower(method), 
26 
case 'linear' 
27 
zi = linear(delau,z); 
28 
% case 'cubic' 
29 
% zi = cubic(x,y,z,xi,yi); 
30 
% case 'nearest' 
31 
% zi = nearest(x,y,z,xi,yi); 
32 
% case {'invdist','v4'} 
33 
% zi = gdatav4(x,y,z,xi,yi); 
34 
otherwise 
35 
error('Unknown method.'); 
36 
end 
37 

38 
if nargout<=1, xi = zi; end 
39 

40 

41 
% 
42 
function zi = linear(del,z) 
43 
%LINEAR Trianglebased linear interpolation 
44 

45 
% Reference: David F. Watson, "Contouring: A guide 
46 
% to the analysis and display of spacial data", Pergamon, 1994. 
47 

48 
z = z(:).'; % Treat z as a row so that code below involving 
49 
% z(tri) works even when tri is 1by3. 
50 
zi = sum(z(del.tri) .* del.w,2); 
51 

52 
zi = reshape(zi,del.siz); 
53 

54 
if ~isempty(del.out), zi(del.out) = NaN; end 
55 

56 
% 