Code covered by the BSD License

# Spectral and XYZ Color Functions

### Jeff Mather (view profile)

01 Mar 2005 (Updated )

Label plots with spectra. Convert wavelengths to RGB. Functions for color matching and illuminants.

illuminant(theIlluminant)
```function [lambda, energy] = illuminant(theIlluminant)
%ILLUMINANT   Standard illuminant values.
%
%    [LAMBDA, ENERGY] = ILLUMINANT(NAME) returns the spectral power density
%    ENERGY at each wavelength in the vector LAMBDA for the illuminant
%    NAME, which can be one of these values:
%
%    A    The standard tungsten filament lamp (2856K)
%    D65  Medium daylight with UV component (6500K)
%    EE   Theoretical equal-energy illuminant
%
%    Reference: http://cvrl.ioo.ucl.ac.uk/
%

%    Copyright 1993-2005 The MathWorks, Inc.

switch(lower(theIlluminant))
case 'a'

values = [300, 0.930483
301, 0.967643
302, 1.005970
303, 1.045490
304, 1.086230
305, 1.128210
306, 1.171470
307, 1.216020
308, 1.261880
309, 1.309100
310, 1.357690
311, 1.407680
312, 1.459100
313, 1.511980
314, 1.566330
315, 1.622190
316, 1.679590
317, 1.738550
318, 1.799100
319, 1.861270
320, 1.925080
321, 1.990570
322, 2.057760
323, 2.126670
324, 2.197340
325, 2.269800
326, 2.344060
327, 2.420170
328, 2.498140
329, 2.578010
330, 2.659810
331, 2.743550
332, 2.829280
333, 2.917010
334, 3.006780
335, 3.098610
336, 3.192530
337, 3.288570
338, 3.386760
339, 3.487120
340, 3.589680
341, 3.694470
342, 3.801520
343, 3.910850
344, 4.022500
345, 4.136480
346, 4.252820
347, 4.371560
348, 4.492720
349, 4.616310
350, 4.742380
351, 4.870950
352, 5.002040
353, 5.135680
354, 5.271890
355, 5.410700
356, 5.552130
357, 5.696220
358, 5.842980
359, 5.992440
360, 6.144620
361, 6.299550
362, 6.457240
363, 6.617740
364, 6.781050
365, 6.947200
366, 7.116210
367, 7.288110
368, 7.462920
369, 7.640660
370, 7.821350
371, 8.005010
372, 8.191670
373, 8.381340
374, 8.574040
375, 8.769800
376, 8.968640
377, 9.170560
378, 9.375610
379, 9.583780
380, 9.795100
381, 10.009600
382, 10.227300
383, 10.448100
384, 10.672200
385, 10.899600
386, 11.130200
387, 11.364000
388, 11.601200
389, 11.841600
390, 12.085300
391, 12.332400
392, 12.582800
393, 12.836600
394, 13.093800
395, 13.354300
396, 13.618200
397, 13.885500
398, 14.156300
399, 14.430400
400, 14.708000
401, 14.989100
402, 15.273600
403, 15.561600
404, 15.853000
405, 16.148000
406, 16.446400
407, 16.748400
408, 17.053800
409, 17.362800
410, 17.675300
411, 17.991300
412, 18.310800
413, 18.633900
414, 18.960500
415, 19.290700
416, 19.624400
417, 19.961700
418, 20.302600
419, 20.647000
420, 20.995000
421, 21.346500
422, 21.701600
423, 22.060300
424, 22.422500
425, 22.788300
426, 23.157700
427, 23.530700
428, 23.907200
429, 24.287300
430, 24.670900
431, 25.058100
432, 25.448900
433, 25.843200
434, 26.241100
435, 26.642500
436, 27.047500
437, 27.456000
438, 27.868100
439, 28.283600
440, 28.702700
441, 29.125300
442, 29.551500
443, 29.981100
444, 30.414200
445, 30.850800
446, 31.290900
447, 31.734500
448, 32.181500
449, 32.632000
450, 33.085900
451, 33.543200
452, 34.004000
453, 34.468200
454, 34.935800
455, 35.406800
456, 35.881100
457, 36.358800
458, 36.839900
459, 37.324300
460, 37.812100
461, 38.303100
462, 38.797500
463, 39.295100
464, 39.796000
465, 40.300200
466, 40.807600
467, 41.318200
468, 41.832000
469, 42.349100
470, 42.869300
471, 43.392600
472, 43.919200
473, 44.448800
474, 44.981600
475, 45.517400
476, 46.056300
477, 46.598300
478, 47.143300
479, 47.691300
480, 48.242300
481, 48.796300
482, 49.353300
483, 49.913200
484, 50.476000
485, 51.041800
486, 51.610400
487, 52.181800
488, 52.756100
489, 53.333200
490, 53.913200
491, 54.495800
492, 55.081300
493, 55.669400
494, 56.260300
495, 56.853900
496, 57.450100
497, 58.048900
498, 58.650400
499, 59.254500
500, 59.861100
501, 60.470300
502, 61.082000
503, 61.696200
504, 62.312800
505, 62.932000
506, 63.553500
507, 64.177500
508, 64.803800
509, 65.432500
510, 66.063500
511, 66.696800
512, 67.332400
513, 67.970200
514, 68.610200
515, 69.252500
516, 69.896900
517, 70.543500
518, 71.192200
519, 71.843000
520, 72.495900
521, 73.150800
522, 73.807700
523, 74.466600
524, 75.127500
525, 75.790300
526, 76.455100
527, 77.121700
528, 77.790200
529, 78.460500
530, 79.132600
531, 79.806500
532, 80.482100
533, 81.159500
534, 81.838600
535, 82.519300
536, 83.201700
537, 83.885600
538, 84.571200
539, 85.258400
540, 85.947000
541, 86.637200
542, 87.328800
543, 88.021900
544, 88.716500
545, 89.412400
546, 90.109700
547, 90.808300
548, 91.508200
549, 92.209500
550, 92.912000
551, 93.615700
552, 94.320600
553, 95.026700
554, 95.733900
555, 96.442300
556, 97.151800
557, 97.862300
558, 98.573900
559, 99.286400
560, 100.000000
561, 100.715000
562, 101.430000
563, 102.146000
564, 102.864000
565, 103.582000
566, 104.301000
567, 105.020000
568, 105.741000
569, 106.462000
570, 107.184000
571, 107.906000
572, 108.630000
573, 109.354000
574, 110.078000
575, 110.803000
576, 111.529000
577, 112.255000
578, 112.982000
579, 113.709000
580, 114.436000
581, 115.164000
582, 115.893000
583, 116.622000
584, 117.351000
585, 118.080000
586, 118.810000
587, 119.540000
588, 120.270000
589, 121.001000
590, 121.731000
591, 122.462000
592, 123.193000
593, 123.924000
594, 124.655000
595, 125.386000
596, 126.118000
597, 126.849000
598, 127.580000
599, 128.312000
600, 129.043000
601, 129.774000
602, 130.505000
603, 131.236000
604, 131.966000
605, 132.697000
606, 133.427000
607, 134.157000
608, 134.887000
609, 135.617000
610, 136.346000
611, 137.075000
612, 137.804000
613, 138.532000
614, 139.260000
615, 139.988000
616, 140.715000
617, 141.441000
618, 142.167000
619, 142.893000
620, 143.618000
621, 144.343000
622, 145.067000
623, 145.790000
624, 146.513000
625, 147.235000
626, 147.957000
627, 148.678000
628, 149.398000
629, 150.117000
630, 150.836000
631, 151.554000
632, 152.271000
633, 152.988000
634, 153.704000
635, 154.418000
636, 155.132000
637, 155.845000
638, 156.558000
639, 157.269000
640, 157.979000
641, 158.689000
642, 159.397000
643, 160.104000
644, 160.811000
645, 161.516000
646, 162.221000
647, 162.924000
648, 163.626000
649, 164.327000
650, 165.028000
651, 165.726000
652, 166.424000
653, 167.121000
654, 167.816000
655, 168.510000
656, 169.203000
657, 169.895000
658, 170.586000
659, 171.275000
660, 171.963000
661, 172.650000
662, 173.335000
663, 174.019000
664, 174.702000
665, 175.383000
666, 176.063000
667, 176.741000
668, 177.419000
669, 178.094000
670, 178.769000
671, 179.441000
672, 180.113000
673, 180.783000
674, 181.451000
675, 182.118000
676, 182.783000
677, 183.447000
678, 184.109000
679, 184.770000
680, 185.429000
681, 186.087000
682, 186.743000
683, 187.397000
684, 188.050000
685, 188.701000
686, 189.350000
687, 189.998000
688, 190.644000
689, 191.288000
690, 191.931000
691, 192.572000
692, 193.211000
693, 193.849000
694, 194.484000
695, 195.118000
696, 195.750000
697, 196.381000
698, 197.009000
699, 197.636000
700, 198.261000
701, 198.884000
702, 199.506000
703, 200.125000
704, 200.743000
705, 201.359000
706, 201.972000
707, 202.584000
708, 203.195000
709, 203.803000
710, 204.409000
711, 205.013000
712, 205.616000
713, 206.216000
714, 206.815000
715, 207.411000
716, 208.006000
717, 208.599000
718, 209.189000
719, 209.778000
720, 210.365000
721, 210.949000
722, 211.532000
723, 212.112000
724, 212.691000
725, 213.268000
726, 213.842000
727, 214.415000
728, 214.985000
729, 215.553000
730, 216.120000
731, 216.684000
732, 217.246000
733, 217.806000
734, 218.364000
735, 218.920000
736, 219.473000
737, 220.025000
738, 220.574000
739, 221.122000
740, 221.667000
741, 222.210000
742, 222.751000
743, 223.290000
744, 223.826000
745, 224.361000
746, 224.893000
747, 225.423000
748, 225.951000
749, 226.477000
750, 227.000000
751, 227.522000
752, 228.041000
753, 228.558000
754, 229.073000
755, 229.585000
756, 230.096000
757, 230.604000
758, 231.110000
759, 231.614000
760, 232.115000
761, 232.615000
762, 233.112000
763, 233.606000
764, 234.099000
765, 234.589000
766, 235.078000
767, 235.564000
768, 236.047000
769, 236.529000
770, 237.008000
771, 237.485000
772, 237.959000
773, 238.432000
774, 238.902000
775, 239.370000
776, 239.836000
777, 240.299000
778, 240.760000
779, 241.219000
780, 241.675000
781, 242.130000
782, 242.582000
783, 243.031000
784, 243.479000
785, 243.924000
786, 244.367000
787, 244.808000
788, 245.246000
789, 245.682000
790, 246.116000
791, 246.548000
792, 246.977000
793, 247.404000
794, 247.829000
795, 248.251000
796, 248.671000
797, 249.089000
798, 249.505000
799, 249.918000
800, 250.329000
801, 250.738000
802, 251.144000
803, 251.548000
804, 251.950000
805, 252.350000
806, 252.747000
807, 253.142000
808, 253.535000
809, 253.925000
810, 254.314000
811, 254.700000
812, 255.083000
813, 255.465000
814, 255.844000
815, 256.221000
816, 256.595000
817, 256.968000
818, 257.338000
819, 257.706000
820, 258.071000
821, 258.434000
822, 258.795000
823, 259.154000
824, 259.511000
825, 259.865000
826, 260.217000
827, 260.567000
828, 260.914000
829, 261.259000
830, 261.602000];

case 'd65'

values = [300, 0.034100
301, 0.360140
302, 0.686180
303, 1.012220
304, 1.338260
305, 1.664300
306, 1.990340
307, 2.316380
308, 2.642420
309, 2.968460
310, 3.294500
311, 4.988650
312, 6.682800
313, 8.376950
314, 10.071100
315, 11.765200
316, 13.459400
317, 15.153500
318, 16.847700
319, 18.541800
320, 20.236000
321, 21.917700
322, 23.599500
323, 25.281200
324, 26.963000
325, 28.644700
326, 30.326500
327, 32.008200
328, 33.690000
329, 35.371700
330, 37.053500
331, 37.343000
332, 37.632600
333, 37.922100
334, 38.211600
335, 38.501100
336, 38.790700
337, 39.080200
338, 39.369700
339, 39.659300
340, 39.948800
341, 40.445100
342, 40.941400
343, 41.437700
344, 41.934000
345, 42.430200
346, 42.926500
347, 43.422800
348, 43.919100
349, 44.415400
350, 44.911700
351, 45.084400
352, 45.257000
353, 45.429700
354, 45.602300
355, 45.775000
356, 45.947700
357, 46.120300
358, 46.293000
359, 46.465600
360, 46.638300
361, 47.183400
362, 47.728500
363, 48.273500
364, 48.818600
365, 49.363700
366, 49.908800
367, 50.453900
368, 50.998900
369, 51.544000
370, 52.089100
371, 51.877700
372, 51.666400
373, 51.455000
374, 51.243700
375, 51.032300
376, 50.820900
377, 50.609600
378, 50.398200
379, 50.186900
380, 49.975500
381, 50.442800
382, 50.910000
383, 51.377300
384, 51.844600
385, 52.311800
386, 52.779100
387, 53.246400
388, 53.713700
389, 54.180900
390, 54.648200
391, 57.458900
392, 60.269500
393, 63.080200
394, 65.890900
395, 68.701500
396, 71.512200
397, 74.322900
398, 77.133600
399, 79.944200
400, 82.754900
401, 83.628000
402, 84.501100
403, 85.374200
404, 86.247300
405, 87.120400
406, 87.993600
407, 88.866700
408, 89.739800
409, 90.612900
410, 91.486000
411, 91.680600
412, 91.875200
413, 92.069700
414, 92.264300
415, 92.458900
416, 92.653500
417, 92.848100
418, 93.042600
419, 93.237200
420, 93.431800
421, 92.756800
422, 92.081900
423, 91.406900
424, 90.732000
425, 90.057000
426, 89.382100
427, 88.707100
428, 88.032200
429, 87.357200
430, 86.682300
431, 88.500600
432, 90.318800
433, 92.137100
434, 93.955400
435, 95.773600
436, 97.591900
437, 99.410200
438, 101.228000
439, 103.047000
440, 104.865000
441, 106.079000
442, 107.294000
443, 108.508000
444, 109.722000
445, 110.936000
446, 112.151000
447, 113.365000
448, 114.579000
449, 115.794000
450, 117.008000
451, 117.088000
452, 117.169000
453, 117.249000
454, 117.330000
455, 117.410000
456, 117.490000
457, 117.571000
458, 117.651000
459, 117.732000
460, 117.812000
461, 117.517000
462, 117.222000
463, 116.927000
464, 116.632000
465, 116.336000
466, 116.041000
467, 115.746000
468, 115.451000
469, 115.156000
470, 114.861000
471, 114.967000
472, 115.073000
473, 115.180000
474, 115.286000
475, 115.392000
476, 115.498000
477, 115.604000
478, 115.711000
479, 115.817000
480, 115.923000
481, 115.212000
482, 114.501000
483, 113.789000
484, 113.078000
485, 112.367000
486, 111.656000
487, 110.945000
488, 110.233000
489, 109.522000
490, 108.811000
491, 108.865000
492, 108.920000
493, 108.974000
494, 109.028000
495, 109.082000
496, 109.137000
497, 109.191000
498, 109.245000
499, 109.300000
500, 109.354000
501, 109.199000
502, 109.044000
503, 108.888000
504, 108.733000
505, 108.578000
506, 108.423000
507, 108.268000
508, 108.112000
509, 107.957000
510, 107.802000
511, 107.501000
512, 107.200000
513, 106.898000
514, 106.597000
515, 106.296000
516, 105.995000
517, 105.694000
518, 105.392000
519, 105.091000
520, 104.790000
521, 105.080000
522, 105.370000
523, 105.660000
524, 105.950000
525, 106.239000
526, 106.529000
527, 106.819000
528, 107.109000
529, 107.399000
530, 107.689000
531, 107.361000
532, 107.032000
533, 106.704000
534, 106.375000
535, 106.047000
536, 105.719000
537, 105.390000
538, 105.062000
539, 104.733000
540, 104.405000
541, 104.369000
542, 104.333000
543, 104.297000
544, 104.261000
545, 104.225000
546, 104.190000
547, 104.154000
548, 104.118000
549, 104.082000
550, 104.046000
551, 103.641000
552, 103.237000
553, 102.832000
554, 102.428000
555, 102.023000
556, 101.618000
557, 101.214000
558, 100.809000
559, 100.405000
560, 100.000000
561, 99.633400
562, 99.266800
563, 98.900300
564, 98.533700
565, 98.167100
566, 97.800500
567, 97.433900
568, 97.067400
569, 96.700800
570, 96.334200
571, 96.279600
572, 96.225000
573, 96.170300
574, 96.115700
575, 96.061100
576, 96.006500
577, 95.951900
578, 95.897200
579, 95.842600
580, 95.788000
581, 95.077800
582, 94.367500
583, 93.657300
584, 92.947000
585, 92.236800
586, 91.526600
587, 90.816300
588, 90.106100
589, 89.395800
590, 88.685600
591, 88.817700
592, 88.949700
593, 89.081800
594, 89.213800
595, 89.345900
596, 89.478000
597, 89.610000
598, 89.742100
599, 89.874100
600, 90.006200
601, 89.965500
602, 89.924800
603, 89.884100
604, 89.843400
605, 89.802600
606, 89.761900
607, 89.721200
608, 89.680500
609, 89.639800
610, 89.599100
611, 89.409100
612, 89.219000
613, 89.029000
614, 88.838900
615, 88.648900
616, 88.458900
617, 88.268800
618, 88.078800
619, 87.888700
620, 87.698700
621, 87.257700
622, 86.816700
623, 86.375700
624, 85.934700
625, 85.493600
626, 85.052600
627, 84.611600
628, 84.170600
629, 83.729600
630, 83.288600
631, 83.329700
632, 83.370700
633, 83.411800
634, 83.452800
635, 83.493900
636, 83.535000
637, 83.576000
638, 83.617100
639, 83.658100
640, 83.699200
641, 83.332000
642, 82.964700
643, 82.597500
644, 82.230200
645, 81.863000
646, 81.495800
647, 81.128500
648, 80.761300
649, 80.394000
650, 80.026800
651, 80.045600
652, 80.064400
653, 80.083100
654, 80.101900
655, 80.120700
656, 80.139500
657, 80.158300
658, 80.177000
659, 80.195800
660, 80.214600
661, 80.420900
662, 80.627200
663, 80.833600
664, 81.039900
665, 81.246200
666, 81.452500
667, 81.658800
668, 81.865200
669, 82.071500
670, 82.277800
671, 81.878400
672, 81.479100
673, 81.079700
674, 80.680400
675, 80.281000
676, 79.881600
677, 79.482300
678, 79.082900
679, 78.683600
680, 78.284200
681, 77.427900
682, 76.571600
683, 75.715300
684, 74.859000
685, 74.002700
686, 73.146500
687, 72.290200
688, 71.433900
689, 70.577600
690, 69.721300
691, 69.910100
692, 70.098900
693, 70.287600
694, 70.476400
695, 70.665200
696, 70.854000
697, 71.042800
698, 71.231500
699, 71.420300
700, 71.609100
701, 71.883100
702, 72.157100
703, 72.431100
704, 72.705100
705, 72.979000
706, 73.253000
707, 73.527000
708, 73.801000
709, 74.075000
710, 74.349000
711, 73.074500
712, 71.800000
713, 70.525500
714, 69.251000
715, 67.976500
716, 66.702000
717, 65.427500
718, 64.153000
719, 62.878500
720, 61.604000
721, 62.432200
722, 63.260300
723, 64.088500
724, 64.916600
725, 65.744800
726, 66.573000
727, 67.401100
728, 68.229300
729, 69.057400
730, 69.885600
731, 70.405700
732, 70.925900
733, 71.446000
734, 71.966200
735, 72.486300
736, 73.006400
737, 73.526600
738, 74.046700
739, 74.566900
740, 75.087000
741, 73.937600
742, 72.788100
743, 71.638700
744, 70.489300
745, 69.339800
746, 68.190400
747, 67.041000
748, 65.891600
749, 64.742100
750, 63.592700
751, 61.875200
752, 60.157800
753, 58.440300
754, 56.722900
755, 55.005400
756, 53.288000
757, 51.570500
758, 49.853100
759, 48.135600
760, 46.418200
761, 48.456900
762, 50.495600
763, 52.534400
764, 54.573100
765, 56.611800
766, 58.650500
767, 60.689200
768, 62.728000
769, 64.766700
770, 66.805400
771, 66.463100
772, 66.120900
773, 65.778600
774, 65.436400
775, 65.094100
776, 64.751800
777, 64.409600
778, 64.067300
779, 63.725100
780, 63.382800
781, 63.474900
782, 63.567000
783, 63.659200
784, 63.751300
785, 63.843400
786, 63.935500
787, 64.027600
788, 64.119800
789, 64.211900
790, 64.304000
791, 63.818800
792, 63.333600
793, 62.848400
794, 62.363200
795, 61.877900
796, 61.392700
797, 60.907500
798, 60.422300
799, 59.937100
800, 59.451900
801, 58.702600
802, 57.953300
803, 57.204000
804, 56.454700
805, 55.705400
806, 54.956200
807, 54.206900
808, 53.457600
809, 52.708300
810, 51.959000
811, 52.507200
812, 53.055300
813, 53.603500
814, 54.151600
815, 54.699800
816, 55.248000
817, 55.796100
818, 56.344300
819, 56.892400
820, 57.440600
821, 57.727800
822, 58.015000
823, 58.302200
824, 58.589400
825, 58.876500
826, 59.163700
827, 59.450900
828, 59.738100
829, 60.025300
830, 60.312500];

case 'ee'

waves = 300:830;
values = [waves' ones(size(waves'))];

otherwise

error('illuminant:unrecognizedIlluminant', ...
'Unrecognized illuminant.')

end

lambda = values(:, 1);
energy = values(:, 2);```