-
Notifications
You must be signed in to change notification settings - Fork 0
/
interpol.m
89 lines (80 loc) · 1.75 KB
/
interpol.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
function y = interpol(x)
%function y = interpol(x)
%
%Interpolates x-matrix values on 'NaN' zones.
y=x;
[ion jon] = find (isnan(x));
for m=1:length(ion)
io=ion(m);
jo=jon(m);
%dip calculation
i=io;
while i > 1
if ~isnan(x(i,jo))
break;
end
i=i-1;
end
dim=io-i;
xim=x(i,jo);
if dim ~= 0
dim = 1. / dim;
end
if isnan(xim)
xim=0;
dim=0;
end
%dim calculation
i=io;
while i < length(x(:,jo))
if ~isnan(x(i,jo))
break;
end
i=i+1;
end
dip=i-io;
xip=x(i,jo);
if dip ~= 0
dip = 1. / dip;
end
if isnan(xip)
xip=0;
dip=0;
end
%djm calculation
j=jo;
while j > 1
if ~isnan(x(io,j))
break;
end
j=j-1;
end
djm=jo-j;
xjm=x(io,j);
if djm ~= 0
djm = 1. / djm;
end
if isnan(xjm)
xjm=0;
djm=0;
end
%djp calculation
j=jo;
while j < length(x(io,:))
if ~isnan(x(io,j))
break;
end
j=j+1;
end
djp=j-jo;
xjp=x(io,j);
if djp ~= 0
djp = 1. / djp;
end
if isnan(xjp)
xjp=0;
djp=0;
end
y(io,jo)= (dim * xim + dip * xip + djm * xjm + djp * xjp) ...
/ (dim + dip + djm + djp);
end