Skip to content

Instantly share code, notes, and snippets.

@jnkather
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jnkather/6de1287c446713266e63 to your computer and use it in GitHub Desktop.
Save jnkather/6de1287c446713266e63 to your computer and use it in GitHub Desktop.
Convert hexadecimal color string to RGB values in Matlab
% (c) Jakob Nikolas Kather 2015
% contact: http://www.kather.me
function rgb = hex2rgb(hexString)
if size(hexString,2) ~= 6
error('invalid input: not 6 characters');
else
r = double(hex2dec(hexString(1:2)))/255;
g = double(hex2dec(hexString(3:4)))/255;
b = double(hex2dec(hexString(5:6)))/255;
rgb = [r, g, b];
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment