Question

I want to create a random value from HeatMap in my project, I'v RGB vector of 1x3, What approach should be appropriate for me for selecting random color, However I created following RGB's colors vector, by what condition I can create a sample of HeatMap using RGB's, I currently need 10 to 15 colors only. What would be the suggestions to create HeatMap scenario in Matlab.

Red = [1 0 0]
Yellow = [1 1 0]
Green = [0 0.5 0]
Cyan = [0 0.5 0.5]
Blue = [0 0 1]
Was it helpful?

Solution

Use allcomb to generate all possible combinations and then select 15 random ones from it -

Code

list_all_colors = allcomb([0 0.5 1],[0 0.5 1],[0 0.5 1])

num_rand_colors = 15 %%// Number of colors needed
rand_colors = list_all_colors(randi(size(list_all_colors,1),num_rand_colors,1),:)

If you don't want to use allcomb and have Neural Network Toolbox, you may use combvec, like this to generate all such combinations (code snippet from here ) -

vectors = {[0 0.5 1], [0 0.5 1], [0 0.5 1]}
list_all_colors = combvec(vectors{:})'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top