Created
June 8, 2015 12:28
-
-
Save jnkather/e06db0ff97a66ccb3c87 to your computer and use it in GitHub Desktop.
Convert RGB color vector to hexadecimal code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% (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