Skip to content

Instantly share code, notes, and snippets.

@jnkather
Created June 8, 2015 12:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jnkather/e06db0ff97a66ccb3c87 to your computer and use it in GitHub Desktop.
Save jnkather/e06db0ff97a66ccb3c87 to your computer and use it in GitHub Desktop.
Convert RGB color vector to hexadecimal code
% (c) JN Kather 2015
function hex = rgb2hex(rgb)
% expects a vector of three elements of RGB color values between 0 and 1.
% Returns a string containing the hex code of the color.
r = uint8(rgb(1)*255);
g = uint8(rgb(2)*255);
b = uint8(rgb(3)*255);
hex = strcat(dec2hex(r,2), dec2hex(g,2), dec2hex(b,2));
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment