you are right! Thanks for pointing out this bug. Seems I have not thoroughly checked the multidimensional support since I've never needed it. I'll correct for it as soon as possible.
I am not sure if the following had been spotted:
In Line 253, when calculating the distances for more than two dimensions, the code was
d = sqrt(sum((X(i,:)-X(j,:)).^2));
I think it should be
d = sqrt(sum((X(i,:)-X(j,:)).^2,2));
as we need the sums of the rows but not the columns. After this correction, everything works perfectly in calculating 3-dimensional variograms.
Many thanks for your function. It is absolutely fabulous!
@vipul utsav: the nugget variance is the variogram value at zero lag distance. You can estimate it visually from the experimental variogram or (better) use variogramfit (http://www.mathworks.de/matlabcentral/fileexchange/25948) to estimate it from the data.
@dd: Right now, this is not possible, but with a minor modification of the function, it is not a problem. Just enter following line in the section where the output for the type 'cloud1' is calculated (Line 202)
S.ij = iid(:,[1 2]);
This gives you the indices for each point pair. You can now take these to calculate e.g. the correlation coefficient for a binned lag distance.
x = rand(1000,1)*4-2;
y = rand(1000,1)*4-2;
z = 3*sin(x*15)+ randn(size(x));
d = variogram([x y],z,'type','cloud1');
% should give you this
distance: [382476x1 double]
val: [382476x1 double]
ij: [382476x2 double]
distbins = unique(d.distance);
% calculate the correlation coefficient
% for the second distance bin
I = d.distance == distbins(2);
Hope it works out for you.