5

If i have a float, for example 0.568 (float is guaranteed to be 0 -> 1). Is there a way to convert that to RGB values (in double [1.0, 1.0, 1.0] or int [255 255 255]) under the current matlab colour scheme (ie. normal, hot, hsv, etc)?

Fantastic Mr Fox
  • 32,495
  • 27
  • 95
  • 175

2 Answers2

5

You can try this:

f = 0.568; % your float

cm = colormap % returns the current color map

colorID = max(1, sum(f > [0:1/length(cm(:,1)):1])); 

myColor = cm(colorID, :) % returns your color

The result for f = 0.568 is

myColor =

    0.8125    1.0000    0.1875
H.Muster
  • 9,297
  • 1
  • 35
  • 46
1

Look at the help for jet.

jet.colors(n) returns an array of n color values spanning the range of the color function, jet in this case. Now all you do is scale/map your data to that 1:n range. This is a good way to get/tweak color maps. I used to do it all the time.

Carlos
  • 1,470
  • 10
  • 18