如何在Matlab中更改聚类点的颜色 [英] How to change color of cluster points in matlab

查看:771
本文介绍了如何在Matlab中更改聚类点的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实现AP聚类算法.我不知道如何为不同的聚类点分配不同的颜色.

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

我的代码段是:

    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.

我该怎么做?

推荐答案

下面是一个示例,该示例如何绘制一个群集中的红色点和一个群集中的绿色加号:

Here is an example for how to plot one cluster in red dots and one in green plus signs:

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

现在只需将数据转换为与cluster1cluster 2(聚类1和聚类2中的点的矩阵)相同的形式,然后就可以绘制它们.

Now just get your data into the same form as cluster1 and cluster 2 (matrices of the points in cluster 1 and cluster 2) and then you can plot them.

假设您没有固定数量的集群.然后,您可以执行以下操作:

Let's say you don't have a fixed number of clusters. Then you can do this:

%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

使用petrichor评论中的 colorspec 上的此链接以了解所有您可以定义不同的符号/颜色组合.

Use this link on colorspec from petrichor's comment to learn about all the different combinations of symbols/colors you can define.

这篇关于如何在Matlab中更改聚类点的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆