function d = dDistances(x,y,z) % dDistances - returns a matrix of distances between points % d = dDistances(x,y,z) % x,y,z - points coordinates matrices with coordinates across column and time along row % d - square matrix of distances between points, or 3D set of square matrices % d(i,j) = sqrt( (x(i)-x(j))^2 + (y(i)-y(j))^2 + (z(i)-z(j))^2) % n = size(x,1); % number of points k = size(x,2); % number of time samples d = zeros(n*k,n); for t = 1:k, deltax = x(:,t)*ones(1,n) - ones(n,1)*x(:,t)'; deltay = y(:,t)*ones(1,n) - ones(n,1)*y(:,t)'; deltaz = z(:,t)*ones(1,n) - ones(n,1)*z(:,t)'; d(n*(t-1)+(1:n), 1:n ) = sqrt(deltax.^2 + deltay.^2 + deltaz.^2); end; return