File Exchange

image thumbnail

Intuitive RGB color values from XKCD

version (53.8 KB) by Chad Greene
RGB triplets for 949 colors, by how they're perceived on a computer monitor and their common names.


Updated 12 Jun 2017

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.

Cite As

Chad Greene (2020). Intuitive RGB color values from XKCD (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (20)

Zhitao GUI

Absolutely fantastic. Thank you for sharing.

Chad Greene

Michael: After downloading the file, unzip it and put the contents in your Current Folder, or your Home Folder (called something like ...Users/myname/Documents/MATLAB). Or you can put it in a folder of its own, and from within Matlab, right-click on the folder and say "Add to Path" and choose the option for the folder and subfolders.

Hey Chad, where do you install on MATLAB after downloading the file? Do you need to install a separate rgb program? For some reason, MATLAB isn't recognizing the data, even when I save the program as an imported variable...

Chad Greene

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...


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

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.

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));

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

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!

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 Compatibility
Created with R2012b
Compatible with any release
Platform Compatibility
Windows macOS Linux