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.


Get the RGB color of monochromatic light

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::fromWaveLength(λ, <γ>)


RGB::fromWaveLength( λ ) returns an approximative RGB specification for light of wavelength λnm.

Light consists of photons, each of which has a distinct wavelength. These different wavelengths cause color perception. RGB::fromWaveLength calculates an RGB triple corresponding to a given wave length.

Different displays show the same RGB color in slightly different ways. For this reason, the so-called "gamma correction" has been invented. RGB::fromWaveLength accepts a second argument, for fine-tuning the assumed gamma correction that enters the calculation.

Color perception depends on a number of factors, including individual differences. Therefore, such a calculation can only return an approximation. RGB::fromWaveLength uses the model published by Dan Bruton for the conversion.

For wavelengths outside the visible spectrum (which ranges from 380 nm to 780 nm), RGB::fromWaveLength returns black.


Example 1

White light, when sent through a prism, is split into the commonly known spectrum, because the prism refracts different wavelengths differently. This spectrum can easily be reproduced by RGB::fromWaveLength:

plot(plot::Raster([[RGB::fromWaveLength(i) $ i=380..780]]),
  Scaling = Unconstrained, Height = 20)

Example 2

Bruton's conversion model looks like this:

  plot::Raster([[RGB::fromWaveLength(i) $ i = 380..780]],
    x = 380..780, y = -0.2..0),
  (x -> RGB::fromWaveLength(x)[i]) $ i = 1..3,
  x = 380..780,
  Colors = [RGB::Red, RGB::Green, RGB::Blue],
  LegendVisible = FALSE,
  XTicksNumber = Low,
  Scaling = Unconstrained,
  Axes = Automatic)



The wavelength: a real-valued constant (interpreted as nanometers) or a length unit


The "gamma correcture" for the display, defaults to 0.8

Return Values

RGB color: a list of three floating-point values

See Also

MuPAD Functions

Was this topic helpful?