MATLAB: Pick random colors from a color map

colormapplot

I have up to 30 variables that may be plotted in 1 figure. There are 2 sets of data, each with 15 variables.
I want to have 2 seperate color maps, so I can identify each set of data.
I initially did this:
cmap1=colormap(hot(15))
cmap2=colormap(winter(15))
However, by doing this, it seems it is just using the first 15 values of each colormap. How would I go about picking 15 random colors out of the whole color map?

Best Answer

Try this:
% Define the two colormaps.
cmap1 = hot(15)
cmap2 = winter(15)
% Combine them into one tall colormap.
combinedColorMap = [cmap1; cmap2]
% Pick 15 rows at random.
randomRows = randi(size(combinedColorMap, 1), [15, 1])
% Extract the rows from the combined color map.
randomColors = combinedColorMap(randomRows, :)
Related Question