2
votes

I have a matrix A in Matlab of size ax2 and a vector class of size ax1. The vector class contains integers from 1 to 237. class(i) tells the class A(i,:) belongs to. For example

clear
rng default
a=10000;
A=randn(a,2);
class=randi(237,a,1);

I would like to do a scatter plot of A(:,1) on A(:,2) assigning the same colour to points in the same class. However, how can I generate 237 colors? I would be fine with having 237 nuances of blue for example, but I don't know if this is even possible in Matlab.

1
Note: class is a MATLAB function. If you use it as a variable, you are hiding the real function, and that may cause serious errors later. I suggest renaming class to class_data or some other non-MATLAB name. - Ander Biguri
Ok, I'll do that, thanks - TEX

1 Answers

2
votes

To generate n amount of colors, the easiest way (if you have no constrains) is to simply get a colormap.

colors=colormap_of_your_choice(n);

Example:

colors=parula(237);

Check MATLABs colormap names here.

I added few more in this FEX submission.

You can find even more in FEX.

You can find how to create your custom colormaps with n colors in this answer.