View License

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

» Watch video

Highlights from
RGB triple of color name, version 2

5.0 | 36 ratings Rate this file 105 Downloads (last 30 days) File Size: 4.46 KB File ID: #24497 Version: 1.1
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,
[2] "Web colors",


This file inspired Custom Colormap, Rgbmap Color Maps, Intuitive Rgb Color Values From Xkcd, Rgbmap(Varargin), and Convert Between Rgb And Color Names.

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 (45)
19 Jan 2017 tianfu xu

Very well! Thanks.

12 Dec 2016 Þorsteinn Markússon

25 Nov 2016 Karina Gutierrez

I am having troubles running the rgb.m, when I try to run it Matlab gives me the following error:
function rgb = rgb(s)

Error: Function definitions are not permitted in this context.

Someone has any ideas? Thanks

Comment only
08 Nov 2016 Julien Reynes

Very helpful! My advice : print the sheet with all colors and save the rgb function in a folder then add this folder with 'set path'. Then it would be very easy to use any color ;)


Comment only
05 Oct 2016 Xinyi Yang

straightforward and very helpful! Thanks a lot!

03 Sep 2016 Carl Reiner

Very easy to use and works perfectly! Thanks a lot

19 Jul 2016 weiwei wu

21 Jun 2016 juan lopez

21 Apr 2016 Pablo

Pablo (view profile)

Really good perfect program!

11 Apr 2016 Stephen Cobeldick

@Artemiy Vyacheslavov: you don't need to "combine" anything. The function that I wrote (at the link you gave) converts in both directions: from RGB to colorname, and also from colorname to RGB.

So why "combine" when my submission does both conversions already? It does not require any supporting functions.

Comment only
30 Mar 2016 Artemiy Vyacheslavov

Combined with the reverse conversion script ( works perfectly!

04 Mar 2016 Donald Chu

Thanks so much. It's great to be able to use more than the basic colors.

23 Nov 2015 SMA

SMA (view profile)

Very helpful!

15 Nov 2015 Nikolay

and it would be even better, if you will consider to add recently updated default colororder used in plots for the list of color shortcuts! thanks

Comment only
15 Nov 2015 Nikolay

works great

20 Aug 2015 Adam Danz

Adam Danz (view profile)

07 Aug 2015 John Trimper

12 May 2015 Ting

Ting (view profile)

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:

Comment only
19 Aug 2014 Chad Greene

Chad Greene (view profile)

By coincidence, this function works with the rgbmap function described here:

Comment only
15 Aug 2014 Jens Richter

Jens Richter (view profile)

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 1.1

VERSION 2 allows finding color name given rgb triple.

Contact us