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
| % Computes 2D variogram {directional or omnidirectional}
% Copyright alghalandis.com | Younes Fadakar Alghalandis
function [h,g,c] = variogram(x,y,v,nL,dir,td)
n = numel(x);
t = zeros(n*(n-1)/2,1);
r = t;
k = 1;
for o=1:n-1 % computes distances and angles
for p=o+1:n
dx = x(p)-x(o);
dy = y(p)-y(o);
t(k) = atan2(dy,dx);
r(k) = sqrt(dx^2+dy^2);
k = k+1;
end
end
L = max(r)/nL; % initialize lag length
g = zeros(1,nL); % initialize gammas with zeros
c = g; % and count of pairs
b = 1;
ta = deg2rad(td); % degree to radian
for a=deg2rad(dir)
for s=1:nL
h = s*L;
th = L/2;
k = 1;
q = 0;
g(b,s) = 0;
c(b,s) = 0;
for o=1:n-1 % computes variogram for different h's
for p=o+1:n
if (abs(r(k)-h)<=th) && (abs(t(k)-a)<=ta)
g(b,s) = g(b,s)+(v(p)-v(o))^2;
q = q+1;
end
k = k+1;
end
end
g(b,s) = g(b,s)/(2*q);
c(b,s) = q;
end
b = b+1;
end
h = (1:nL)*L; % returns lags as h vector |
Partager