plot_mst.m

来自「support vector clustering for Matlab too」· M 代码 · 共 39 行

M
39
字号
%==========================================================================
%   Create Minimum Spanning Tree (MST) and plotting
%==========================================================================
%  Example
%
%  [T]=plot_mst(x)   % x: N x dim
%
%==========================================================================
% January 13, 2009
% Implemented by Daewon Lee
% WWW: http://sites.google.com/site/daewonlee/
%==========================================================================
function [T]=plot_mst(x)

edge=[]; cost=[];
for i=1:size(x,1)
    for j=1:size(x,1)
        if i<j
            edge=[edge; i j];
            cost=[cost; dist2(x(i,:),x(j,:))];
        end
    end
end

T=mst(edge,cost);

[num dummy]=size(T);

if size(x,2)==2
    figure;
    hold on
    for i=1:num
        temp=[x(T(i,1),:);x(T(i,2),:)];
        plot(temp(:,1),temp(:,2));
    end
    title('Proximity graph by Minimum Spanning Tree (MST)');
    hold off
end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?