0

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]

1 Answers1

0

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{:})'
Community
  • 1
  • 1
Divakar
  • 218,885
  • 19
  • 262
  • 358
  • all combinations may full fill the HeatMap phenonmena, i.e light blue,blue and dark blue type color combinations? I think it may contain duplicates or irrelevant colors. –  Apr 21 '14 at 17:56
  • @AhsanAli You were right! Check out **Edit 1**. One thing I would like to add to it is that you can have more colors to choose from if you let something like `0.25` or `0.75` come into the input vectors. – Divakar Apr 21 '14 at 18:01
  • it gives me error of, Undefined function 'allcomb' for input arguments of type 'double'. –  Apr 21 '14 at 18:04
  • You need to get `allcomb` function from [here](http://www.mathworks.in/matlabcentral/fileexchange/10064-allcomb) or use `combvec` approach mentioned in the solution. Fixed in **Edit 1**. Hope it works! – Divakar Apr 21 '14 at 18:05
  • Yeah it works, but gives 15x27 matrix of random colors having redundant values. –  Apr 21 '14 at 18:11
  • Think you missed that very important transpose sign `'` at the end of `list_all_colors = combvec(vectors{:})'`. – Divakar Apr 21 '14 at 18:16