All you need to do is interpolate your values according to your caxis and colormap, bearing in mind that value outside the caxis range are clamped to that range:
scalar = [0; 7; 4; 10; 2]
climits = caxis;
cmap = colormap;
scalarclamped = scalar;
scalarclamped(scalar < climits(1)) = climits(1);
scalarclamped(scalar > climits(2)) = climits(2);
rgb = interp1(linspace(climits(1), climits(2), size(cmap, 1)), ...
cmap, ...
scalarclamped)
Best Answer