Approach 1: Create a legend
symbs= {'r+','g.','bv','m*','ko'};
figure;
hold on
for i = 1: length(I)
plot(X(I(i),1),X(I(i),2),symbs{i},'MarkerSize',20)
plot(X(C==i,1),X(C==i,2),symbs{i})
end
labels = {'Cluster 1','Cluster 2','Cluster 3','Cluster 4','Cluster 5'};
legend(labels);
Since you're plotting two graphics objects with each symbol, you will (probably) find that
this doesn't look quite right: There will be two repetitions of each symbol in the legend rather than one. To solve this, store the handles of one of the sets of objects, and use the handles as the first argument to legend
.
for i = 1: length(I)
h(i) = plot(X(I(i),1),X(I(i),2),symbs{i},'MarkerSize',20);
plot(X(C==i,1),X(C==i,2),symbs{i})
end
labels = {'Cluster 1','Cluster 2','Cluster 3','Cluster 4','Cluster 5'};
legend(h, labels(1:length(h)) );
Approach 2: Use annotation
Annotation lets you do things like draw arrows or place text boxes containing identifying information onto your plots. See the link for the options, and an example.