5.0 | 22 ratings Rate this file 159 Downloads (last 30 days) File Size: 4.46 KB File ID: #24497
image thumbnail

RGB triple of color name, version 2



20 Jun 2009 (Updated )

Returns a Matlab RGB color specifier corresponding to a given color name (139 colors supported).

| Watch this File

File Information

RGB = RGB('COLORNAME') returns the red-green-blue triple corresponding to the color named COLORNAME by the CSS3 proposed standard [1], which contains 139 different colors (an rgb triple is a 1x3 vector of numbers between 0 and 1). The color names are the ones accepted by almost all web browsers, for example Brown, DarkRed, SlateGray.

RGB CHART creates a figure window showing all the available colors with their names.

COLORNAME = RGB(r,g,b) and COLORNAME = RGB([r,g,b]) both find the name of the color with the triple that is closest to [r,b,g] (measured by sum of squares).

  c = rgb('DarkRed') gives c = [0.5430 0 0]
  c = rgb('Green') gives c = [0 0.5 0]
  plot(x,y,'color',rgb('orange')) plots an orange line through x and y
  rgb chart shows all the colors
  cnam = rgb(0.8,0.3,0.3) gives cnam = 'IndianRed'

[1] "CSS Color module level 3", W3C (World Wide Web Consortium) working draft 21 July 2008, http://www.w3.org/TR/css3-color.
[2] "Web colors", http://en.wikipedia.org/wiki/Web_colors


This file inspired To Ppt, Custom Colormap, Rgbmap Color Maps, Intuitive Rgb Color Values From Xkcd, and Name That Color! Rgb < > Colorname Converter.

MATLAB release MATLAB 7.7 (R2008b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (27)
18 Oct 2014 Stephen Cobeldick

As some commenters have noted, this submission does not match RGB -> colornames. I wrote a color identifier function to convert between RGB and colornames (both ways):


The user can also choose the to match RGB values using least-squares, or one of the color-difference methods CMC2:1, CIE76, or CIE94 (the default). A bonus function is also included that demonstrates that differences between these matching methods. For more info see also: https://en.wikipedia.org/wiki/Color_difference

Comment only
19 Aug 2014 Chad Greene

Chad Greene (view profile)

By coincidence, this function works with the rgbmap function described here: http://www.mathworks.com/matlabcentral/fileexchange/46874-rgbmap-color-maps/content/rgbmapdemo/html/rgbmap_demo.html

Comment only
15 Aug 2014 Jens Richter

Very useful :-)

13 Aug 2014 Brian

Brian (view profile)

04 Aug 2014 Philippe


12 May 2014 Pit D

Pit D (view profile)

08 May 2014 Dimitra Zarbouti

Very useful. Thanks!

25 Mar 2014 schwarzkater

Great!! very useful.

Comment only
11 Feb 2014 Isaak

Isaak (view profile)

22 Jan 2014 Antonio  
06 May 2013 Bardia

Bardia (view profile)

Great function! Very helpful.

As others have mentioned the colorname = rgb(r, g, b) has not been implemented though!

Comment only
17 Apr 2013 Katarzyna Zarnowiec  
05 Mar 2013 Benjamin Bayes

Highly useful function! However, your Version 2 seems to have not been uploaded. The current function will not accept 3 inputs [R,G,B] to return a color name, as you describe. Please update!

02 Mar 2013 Pio Nonus

At last an easy way to select Matlab colors. Before your script it was frustrating.

12 Feb 2013 Bahman Abbasi

Very useful. Given the frustratingly few default choices in Matlab, this can extend your lifespan by a few day!

10 Oct 2012 SeungGyu cho

cool~, I was looking for this, thank you.

15 Feb 2012 John Trimper

so great.

22 Apr 2011 Wafa BEN RHOUMA  
21 Apr 2011 Feda

Feda (view profile)

17 Feb 2011 Ryan Stanley

This is a great tool however I am having a few issues. When I use your example code:

cnam = rgb(0.8,0.3,0.3)

Matlab returns:

??? Error using ==> rgb
Too many input arguments.

Any ideas?

Comment only
30 Jun 2010 Darwin@cal Chang

Great job!

11 Jun 2010 April Warnock

This is great! Thanks so much!

04 Feb 2010 Richard Crozier

very handy, thanks!

27 Aug 2009 K R

K R (view profile)

this is so simple and brilliant!!! What a massive time-saver and figure-improver!! A million thanks!!

19 Aug 2009 Sabine

Sabine (view profile)

08 Jul 2009 Husam Aldahiyat


22 Jun 2009 us

us (view profile)

excellent in-depth help including many references...
easily expandable look-up table engine...
certainly very useful for color-freaks...

05 Jul 2009

VERSION 2 allows finding color name given rgb triple.

Contact us