-
Notifications
You must be signed in to change notification settings - Fork 0
/
griddata_v4.m
38 lines (28 loc) · 954 Bytes
/
griddata_v4.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
function [xq,yq,vq] = griddata_v4(x,y,v,xq,yq)
%GDATAV4 MATLAB 4 GRIDDATA interpolation
% Reference: David T. Sandwell, Biharmonic spline
% interpolation of GEOS-3 and SEASAT altimeter
% data, Geophysical Research Letters, 2, 139-142,
% 1987. Describes interpolation using value or
% gradient of value in any dimension.
xy = x(:) + 1i*y(:);
% Determine distances between points
d = abs(xy - xy.');
% Determine weights for interpolation
g = (d.^2) .* (log(d)-1); % Green's function.
% Fixup value of Green's function along diagonal
g(1:size(d,1)+1:end) = 0;
weights = g \ v(:);
[m,n] = size(xq);
vq = zeros(size(xq));
xy = xy.';
% Evaluate at requested points (xq,yq). Loop to save memory.
for i=1:m
for j=1:n
d = abs(xq(i,j) + 1i*yq(i,j) - xy);
g = (d.^2) .* (log(d)-1); % Green's function.
% Value of Green's function at zero
g(d==0) = 0;
vq(i,j) = g * weights;
end
end