IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
color2hex.m
Go to the documentation of this file.
1 %>@ingroup conversion graphicsapi
2 %>@file
3 %>@brief Generates color string in HTML hexadecimal style
4 %
5 %> @param x 3-element vector, each element between 0 and 1
6 %> @return a 6-caracter string
7 function z = color2hex(x)
8 if numel(x) ~= 3
9  error('Three numbers please');
10 end;
11 if sum(x > 1 | x < 0)
12  error('Between 0 and 1 please');
13 end;
14 if size(x, 1) > 1
15  x = x';
16 end;
17 z = dec2hex(floor([1 x]*255)); % Addex 1 so that MATLAB generates 2-digit hexadecimals
18 z = z(2:end, :)';
19 z = z(:)';
function color2hex(in x)