View License

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

» Watch video

Highlights from
Intuitive RGB color values from XKCD

4.8 | 6 ratings Rate this file 17 Downloads (last 30 days) File Size: 30.3 KB File ID: #46872 Version: 1.4
image thumbnail

Intuitive RGB color values from XKCD


Chad Greene (view profile)


05 Jun 2014 (Updated )

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

| Watch this File

File Information

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.


Rgb Triple Of Color Name, Version 2, Generate Maximally Perceptually Distinct Colors, Cbrewer : Colorbrewer Schemes For Matlab, Xkcdify, Rgb2hex And Hex2rgb, and Megan Simulator (Xkcd) inspired this file.

This file inspired Rgbmap Color Maps, Post Glacial Rebound, Colorpicker, Cubehelix Colormaps: Beautiful, Distinct, Versatile!, Color Brewer: Attractive And Distinctive Colormaps, How To Estimate Subglacial Water Routes, Cyclic Color Map, and Convert Between Rgb And Color Names.

Required Products MATLAB
MATLAB release MATLAB 8.0 (R2012b)
MATLAB Search Path
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (10)
15 Mar 2016 Kevin

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.

30 Jul 2015 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.

Comment only
28 Jul 2015 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));

Comment only
28 Jul 2015 Florian Klimm

12 Feb 2015 Rajesh Rajaram

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

08 Aug 2014 Stephen Cobeldick

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

Comment only
08 Aug 2014 Stephen Cobeldick

08 Aug 2014 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.

Comment only
08 Aug 2014 Stephen Cobeldick

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

24 Jun 2014 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!

05 Jun 2014 1.1

Link to hex2rgb, rgb2hex.

07 Aug 2014 1.2

Now supports multiple inputs and offers help for misspelled inputs.

08 Aug 2014 1.3

Included hex2rgb function and improved error handling.

30 Jul 2015 1.4

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

Contact us