File Exchange

image thumbnail

Intuitive RGB color values from XKCD

version 1.5 (53.8 KB) by

RGB triplets for 949 colors, by how they're perceived on a computer monitor and their common names.



View License

This function returns the RGB triplet for almost any color. And unlike the way colors are somewhat officially defined (, this data set describes returns values for the ways that colors are actually perceived on computer monitors. Color names are intuitive because they are based on a survey of over 200,000 user sessions, wherein respondents were shown colors and asked to fill in their word for that color. You won't find "puke green" on Wikipedia's list of web colors, despite the fact that it's a color name that people use and understand.

Data come from an XKCD survey described here:
A chart of available colors and their most common names can be found here:

RGB = rgb('Color Name')
RGB = rgb('Color Name 1','Color Name 2',...,'Color Name N')
RGB = rgb({'Color Name 1','Color Name 2',...,'Color Name N'})

RGB = rgb('Color Name') returns the RGB triplet for a color described by 'Color Name'.

RGB = rgb('Color Name 1','Color Name 2',...,'Color Name N') returns an N by 3 matrix containing RGB triplets for each color name.

RGB = rgb({'Color Name 1','Color Name 2',...,'Color Name N'}) accepts list of color names as a character array.

Comments and Ratings (12)

Chad Greene

Chad Greene (view profile)

Hi Taisiya, Thanks for pointing out this oversight! I'm not sure how that happened. The updated version should work.

When I download the file, it contains neither xkcd_rgb_data.mat not rgb.txt files...


Kevin (view profile)

Great function, I use it all the time. I like the bit that finds near matches if you spell a color wrong. It does a good job so I just edited rgb.m to choose the first-listed nearby name rather than ask me to correct the spelling.

Chad Greene

Chad Greene (view profile)

Thanks for catching this error and tracking down the cause, Florian! I've made the fix you suggest, and I moved the installation script to the rgb function itself.

Florian Klimm

Very good tool.
It might be a problem with Mac or the version of Matlab I am using (R2014b) but I had to change the following lines in the hex2rgb.m since I got an error with the '#' sing not being properly deleted from the string.

%if strcmpi(hex(1,1),'#')
% hex(:,1) = [];
r = hex2dec(hex(:,2:3));
g = hex2dec(hex(:,4:5));
b = hex2dec(hex(:,6:7));

Florian Klimm

Nifty code. One that's sorely needed in Matlab. Thanks for the submission.

PPS: the input checking <iscellstr(ColorNames)==0 && iscellstr({ColorNames})==1> is equivalent to <ischar(ColorNames)> :)

Chad Greene

Chad Greene (view profile)

Great catch Stephen, thanks for bringing this to my attention. I neglected to include hex2rgb in yesterday's update. It's now included.

PS: although the function "hex2rgb" should either be included, or otherwise clearly indicated that it is required!

Stephen Cobeldick

This is a very tidy submission. The original XKCD survey makes for a highly entertaining read, and this submission (an import of the survey results into MATLAB) is a great addition by Chad Greene to the MATLAB color handling functions!



The rgb data are now included in the zip file.


Fixed a bug in the installation script. Installation is now performed fully within the rgb function.


Included hex2rgb function and improved error handling.


Now supports multiple inputs and offers help for misspelled inputs.


Link to hex2rgb, rgb2hex.

MATLAB Release
MATLAB 8.0 (R2012b)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Win prizes and improve your MATLAB skills

Play today