I want to convert any number 0<=f<=1
to a rbg code given by four categories green, yellow, orange and red
. I can achieve that with the following function:
function [rgb,myColor]=colorCode(f)
cm = [0 1 0;1 1 0;255/255 153/255 51/255;1 0 0];
colorID = max(1, sum(f > [0:1/length(cm(:,1)):1]));
myColor = cm(colorID, :);
rgb = uint8(myColor*255+0.5);
Now, I will like to do 2 improvements to this:
1.- Above code will divide the interval [0,1] in four equal parts, that is:
[0,0.25]>green
[0.25,0.5]>yellow
[0.5,0.75]>orange
[0.75,1]>red
But I will like to define custom intervals, for instance:
[0,0.3]>green
[0.3,0.5]>yellow
[0.5,0.7]>orange
[0.7,1]>red
2.- I would like that the transition between color intervals to be more smooth. Right now, between 0.25 and 0.26 color changes suddenly from green to yellow. The idea would be to go from green to green-yellow-ish to yellow-green-ish to yellow, and the analogous for the other transitions. I now I have to add more rows to the cm colormap matrix, but I have no idea how....