1

I am implementing AP clustering algorithm. I don't know how to assign different colors to different cluster points.

My code segment is:

    I=find(diag(E)>0) %  Find number of cluster head
    K=length(I); %cluster head
    fprintf('Number_of_clusters:''%d',length(I))
    [tmp c]=max(distance(:,I),[],2);
    c(I)=1:K ;              
    idx=I(c)
    for k=1:K
    ii=find(c==k)% cluster points
    end;

I have to set a different color to different cluster members like red for cluster one, blue for second one and so on.

How can I do this?

4

1 に答える 1

4

1 つのクラスターを赤い点で、もう 1 つのクラスターを緑のプラス記号でプロットする方法の例を次に示します。

n = 100;
cluster1 = randn([n,2]); % 100 2-D coordinates 
cluster2 = randn([n,2]); % 100 2-D coordinates 
hold on
plot(cluster1(:,1),cluster1(:,2),'r.'); %plotting cluster 1 pts
plot(cluster2(:,1),cluster2(:,2),'g+'); %plotting cluster 2 pts

ここに画像の説明を入力

cluster1ここで、データをand cluster 2(クラスター 1 とクラスター 2 の点の行列)と同じ形式にするだけで、それらをプロットできます。

クラスタの数が決まっていないとしましょう。次に、これを行うことができます:

%Defines some order of colors/symbols
symbs = {'r.', 'g+','m*','b.','ko','y+'}; 

figure(1)
hold on
for i = 1:num_clusters,
   % Some code here to extract the coordinates in one particular cluster...
   plot(cluster(:,1),cluster(:,2),symbs{i});
end

ペトリコールのコメントのcolorspecでこのリンクを使用して、定義できるシンボル/色のさまざまな組み合わせについて学習してください。

于 2012-05-25T06:08:53.537 に答える