## code problem of semivariogram

### vipul utsav (view profile)

on 6 Jan 2013
clc;
close all;
clear all;
x=10+sqrt(50)*randn(400,1);
y=2+sqrt(30)*randn(400,1);
[a,b]=size(x);
d=a/40;           %lag distance separation
num=a/d;
for i=1:num
l=(x(1)-x(d))^2+ (y(1)-y(d))^2+ (y(1)-y(d))^2;
lam(i)=(0.5*l)/3;              %varigram calculation
di(i)=d;
d=d+10;
end
marker = 'o--';
plot(di,lam,marker);
axis([0 400 0 max(lam)*1.1]);
xlabel('h');
ylabel('\gamma (h)');
title('(Semi-)Variogram');

is this right way to calculate semivariogram of image?

### Roger Stafford (view profile)

on 6 Jan 2013
Edited by Roger Stafford

### Roger Stafford (view profile)

on 6 Jan 2013

Based on my brief reading of varigrams there appear to be a number of objections to this calculation. First, if your stochastic process is gaussian as indicated by your use of 'randn', the values obtained should be exact as for example is done in a variance computation, and not dependent on a random number generator. Second, the result should be a function of two variables, not one as you have here, particularly since your x and y variables possess different standard deviations. Third, the mean values are supposed to be removed before subtraction is done. Fourth, you have added (y(1)-y(d))^2 twice and I can see no reason for that. Fifth, why multiply by .5/3 ? What is the reason for that?

vipul utsav

### vipul utsav (view profile)

on 7 Jan 2013
variogram(v)=(sum((z(x)-z(x+h))^2))/(2*m)

where, h is lag distance and m is number of pairs and z(x) and z(x+h) is a DN value at x and x+h location in row,,,here i have selected two row,,

and therefore m=2 pair for same lag distance,so i multipy sum with 0.5/2

clc;
close all;
clear all;
x=10+sqrt(50)*randn(400,1);
y=2+sqrt(30)*randn(400,1);
[a,b]=size(x);
d=a/40;            %lag distance separation
num=a/d;
for i=1:num
l=(x(1)-x(d))^2+ (y(1)-y(d))^2;
lam(i)=(0.5*l)/2;  %(sum((z(x)-z(x+h))^2))/(2*m)
di(i)=d;
d=d+10;
end
marker = 'o--';
plot(di,lam,marker);
axis([0 400 0 max(lam)*1.1]);
xlabel('h');
ylabel('\gamma (h)');
title('(Semi-)Variogram');

i request to you if you have studied brief please provide me a correct code