24小时热门版块排行榜    

CyRhmU.jpeg
查看: 1155  |  回复: 0

xiaxiaozhi

新虫 (初入文坛)

[求助] matlab的聚类分析

n = 300 ;
c = 3;
t = randperm(n) ;
x = [randn(1,n/3)-2 randn(1,n/3) randn(1,n/3)+2 ;
     randn(1,n/3) randn(1,n/3)+4 randn(1,n/3)]' ;

m = x(t(1:c), ;
x2 = sum(x.^2,2) ;
s0(1:c,1)=inf;
for o = 1 : 100
        m2 = sum(m.^2,2) ;
        [d,y] = min(repmat(m2,1,n)+repmat(x2',c,1)-2*m*x') ;
        for j = 1 : c
            m(j, = mean(x(y==j,) ;
           s(j,1) = mean(d(y==j)) ;
        end
        % norm(A) 返回矩阵A的二范数
        % 矩阵的二范数 : A' * A 的最大特征值开平方
        % A = [0 1 2 ; 3 4 5 ; 6 7 8] ;
        % norm(A) = sqrt(max(eig(A'*A))) = 14.2267
        if norm(s-s0) < 0.001
            break ;
        end
        s0 = s ;
end
figure(1) ;%创建图形窗口
clf ;%清除当前图像窗口
hold on ;
plot(x(y==1,1),x(y==1,2),'bo') ;
plot(x(y==2,1),x(y==2,2),'rx') ;
plot(x(y==3,1),x(y==3,2),'gv') ;

本人初学者,有点看不懂,尤其是从for开始,不知道聚类为什么这样写,请赐教
回复此楼
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 xiaxiaozhi 的主题更新
信息提示
请填处理意见