function [class]=dbscannew(X,k,eps)
[m,n]=size(X);
class=zeros(1,m);
clusterId = 0;
X=[class',X];
for i = 1:m
clusterId = clusterId + 1;
if X(i,1) == 0
[X]=expandcluster(i,X,clusterId,eps,k,n);
end
end
class = X(:,1)';
function [X]=expandcluster(index,X,clusterId,eps,k,n)
Di=dist(X(index,(2:n)),X(:,(2:n)));
D = find(Di==k)
for i = 1: length(Result)
if X(Result(i),1) == 0|-1
if X(Result(i),1)==0
D(length(D)+1)=Result(i);
end
X(Result(i),1)=clusterId;
end;
end;
end;
D(1)=[];
end;
end;
%function distan = dist(x,y)
% sum = 0;
%nx = size(x);
%for i = 1:nx
% sum = (x(i)-y(i))^2+sum;
%end
%distan = sqrt(sum)
%............................................
function [Di]=dist(i,x)
% function: [D]=dist(i,x)
%
% Aim:
% Calculates the Euclidean distances between i and all objects in x
%
% Input:
% i - an object (1,n)
% x - data matrix (m,n); m-objects, n-variables
%
% Output:
% D - Euclidean distance (m,1)
[m,n]=size(x);
Di=sqrt(sum((((ones(m,1)*i)-x).^2)'));
if n==1
Di=abs((ones(m,1)*i-x))';
end