I am given some points and some centroids representing the centers of some clusters of points. I am asked to determine what cluster each point belongs to and then plot it (using scatter3), and each cluster of points should be colored differently.
How can I generate an initial cluster_colors matrix of size Cx3, where C is the number of clusters/ centroids? It doesn’t really matter what the colors are, but they should be easily distinguishable. Also, I don’t know the number of clusters beforehand.
To color the points with SCATTER3 you actually need Nx1 matrix (
CLRin the example below), there N is the number of points. This matrix can contain the cluster number, for example.The colors will be used from the current colormap. To set the colormap you do need a Cx3 matrix. You can get it from any existing colormap. See COLORMAP for more details.
For example,
Actually the number of colors in the colormap don’t have to be equal to the number of clusters.
You can also create your own colormap using MATLAB colormap editor. Or find many nice colormaps on the FileExchange, like this one.