using dbscan to clustering in matlab

源代码在线查看: dbscannew.m

软件大小: 2 K
上传用户: ldh_ncu10
关键词: clustering dbscan matlab using
下载地址: 免注册下载 普通下载 VIP

相关代码

				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 
				
							

相关资源