This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Find names of predefined colors

MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.


RGB::colorName(rgb, <Exact>)


RGB::colorName([r, g, b]) looks for the predefined color with values closest to [r, g, b] and returns its name.

RGB::colorName([r, g, b], Exact) looks for a predefined color with values exactly [r, g, b] and returns its name.

The RGB namespace contains predefined color names, accessible as RGB::Blue etc. RGB::colorName performs a reverse lookup, finding the name of a color given as RGB values.

Since rather often, colors will stem from calculations with floating-point numbers, no exact matches can be expected in this reverse lookup. Therefore, by default, RGB::colorName will perform a "fuzzy" search, returning the predefined color which is closest (in Euclidean distance in RGB space) to the input. Cf. Example 2.


Example 1

RGB::colorName returns the symbolic name of predefined colors:

RGB::colorName([0, 1, 0])

RGB::colorName([0, 1, 0, 0.5])

Example 2

When performing calculations on color values, the results will rarely be exact, even if the unavoidable round-off errors are too small to be displayed on the screen:

a := RGB::Olive;
b := RGB::fromHSV(RGB::toHSV(RGB::Olive))

bool(a = b)

Therefore, RGB::colorName by default searches in a "fuzzy" fashion:


In cases where this is undesirable, the option Exact can be used to switch to exact searching:

RGB::colorName(a, Exact);
RGB::colorName(b, Exact)

The predefined color names do not fill RGB space uniformly, therefore, the color found by RGB::colorName may be quite different from the one entered. The following plot shows the predefined colors in RGB space:

  plot::PointList3d([c.[c] $ c in RGB::ColorList]),
  ZXRatio = 1, BackgroundStyle = TopBottom,
  BackgroundColor = RGB::Grey,
  BackgroundColor2 = RGB::White,



An RGB or RGBa color specification: A list of three or four real numbers in the interval .



Only return an exact match, FAIL if none exists.

Return Values

If a color was found, RGB::colorName returns an expression of the form RGB::Name or RGB::Name.[a]. If given Exact and no match was found, FAIL is returned. If given symbolic input parameters, an unevaluated call is returned.

See Also

MuPAD Functions

Was this topic helpful?