Reputation: 8461
Say I have the following Time Series:
a = [1 3 1 5 1 3 5 1 5];
Now, on doing kmeans(a,3), I obtained:
b = kmeans(a,3); // [1 2 1 3 1 2 3 1 3];
based on the clusters.
I now wish to plot a, so that the color for a(i) corresponds to the cluster that is has been assigned in b. Can someone show me how to do that?
Upvotes: 0
Views: 69
Reputation: 112749
This plots each point with increasing x coordinates, y coordinate equal to a
, and the color as given by b
:
colors = hsv(max(b)); %// or use other color maps:
hold on
for ii = 1:length(a)
plot(ii,a(ii),'marker', 'o', 'color',colors(b(ii),:)) %// option 1
end
axis([0 length(a+1) min(a)-1 max(a)+1])
Upvotes: 1