我写了个最短距离的小程序.可是一直调不成功.哪位大虾帮忙看看?
%std1.m,用极差标准化法标准化矩阵 <BR>function std=std1(vector) <BR>max=max(vector'); %对列求最大值 <BR>min=min(vector); <BR>=size(vector); %矩阵大小,a为行数,b为列数<BR>for i=1:a <BR> for j=1:b <BR> std(i,j)= (vector(i,j)-min(j))/(max(j)-min(j)); <BR> end <BR>end <BR>%min1.m,求矩阵中最小值,并返回行列数及其值 <BR> function =min1(vector);%v1为行数,v2为列数,v3为其值 <BR> =min(min(vector')); <BR> =min(min(vector)); <BR> v3=min(min(vector)); <BR> %min2.m,比较两数大小,返回较小的值 <BR> function v1=min(v2,v3);<BR> if v2>v3<BR>v1=v3; <BR>else <BR> v1=v2; <BR>end <BR>clear all<BR>clc<BR>vector=;<BR>vector=ds1(vector); <BR>=size(vector); <BR>d=zeros(a); <BR>for i=1:a <BR> for j=1:a <BR> for k=1:b <BR> d(i,j)=d(i,j)+abs(vector(i,k)-vector(j,k)); <BR> end<BR> end <BR> end <BR> <BR>=size(vector); <BR>max=max(max(vector)); <BR>for i=1:a <BR> for j=i:b <BR> vector(i,j)=max; <BR> end <BR>end; <BR>while g>12<BR>=size(vector); <BR> =min1(vector); <BR> for l=1:c <BR> if l<=min2(e,f) <BR> vector(c+1,l)=min2(vector(e,l),vector(f,l)); <BR> else <BR> vector(c+1,l)=min2(vector(l,e),vector(l,f)); <BR> end <BR> end; <BR> vector(1:c+1,c+1)=max;<BR> vector(1:c+1,e)=max; <BR> vector(1:c+1,f)=max; <BR> vector(e,1:c+1)=max; <BR> vector(f,1:c+1)=max; <BR>end <BR>vector2(2,c)=;<BR>if e<=c<BR> vector2(2,c)=1;<BR>end<BR>if f<=c<BR> vector2(2,f)=1;<BR>end<BR>m=[];<BR>if e<=c&f>c<BR> m=<BR>end<BR>if e<=c&f<=c<BR> m=<BR>end<BR> if e<=c&f<=c<BR> m=m+1;<BR> m=;<BR> end;<BR> end<BR>for j=1:c<BR> if vector2(2,j)==0<BR> n=m+j;<BR>n=n+1;<BR> end<BR>end 是最短距离聚类的程序回复:(fenghongpe)我写了个最短距离的小程序.可是一...
你的那个程序好长啊,最短距离聚类参考下面的代码吧<BR><BR>function result=cluster(vector); <BR>=size(vector); <BR>maxv=max(max(vector)); <BR>for i=1:a <BR>for j=i:b <BR>vector(i,j)=maxv; <BR>end <BR>end; <BR>for k=1:(b-1) <BR>=size(vector); <BR>fprintf('第%g次聚类:\n',k); <BR>=min1(vector); <BR>fprintf('最小值=%g,将第%g区和第%g区并为一类,记作G%g\n\n',g,e,f,c+1); <BR>for l=1:c <BR>if l<=min2(e,f) <BR>vector(c+1,l)=min2(vector(e,l),vector(f,l)); <BR>else <BR>vector(c+1,l)=min2(vector(l,e),vector(l,f)); <BR>end <BR>end; <BR>vector(1:c+1,c+1)=maxv; <BR>vector(1:c+1,e)=maxv; <BR>vector(1:c+1,f)=maxv; <BR>vector(e,1:c+1)=maxv; <BR>vector(f,1:c+1)=maxv; <BR>end
页:
[1]