使用matlab颜色方案将float转换为RGB

Fan*_*Fox 5 matlab colors

如果我有一个浮动,例如0.568(保证浮动0 -> 1).有没有办法在当前的matlab颜色方案(即普通,热,hsv等)下将其转换为RGB值(双精度[1.0, 1.0, 1.0]或整数[255 255 255])?

H.M*_*ter 5

你可以试试这个:

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
Run Code Online (Sandbox Code Playgroud)

结果f = 0.568

myColor =

    0.8125    1.0000    0.1875
Run Code Online (Sandbox Code Playgroud)