How to change color of cluster points in matlab

后端 未结 1 1695
有刺的猬
有刺的猬 2021-01-15 22:59

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(d         


        
相关标签:
1条回答
  • 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
    

    enter image description here

    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
    

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

    0 讨论(0)
提交回复
热议问题