makergb
Version 3.0.0.1 (4,95 KB) von
Andres
multidimensional numeric RGB color array from mixed inputs
makergb creates a numeric RGB color array from different (mixed) input elements, including 3- and 6-digit hexadecimal color codes and pre-defined color names.
makergb can handle multidimensional inputs and returns the RGB triplet between 0 and 1 along the highest dimension. It returns a (customizable) default value for missing or non-interpretable input elements.
Pre-defined color names comprise short and long names from Matlab's ColorSpec plus a few extensions including the current and previous Matlab default colors (overall 32 different colors, see image). The emphasis is not on exhaustive color name conversion; for that purpose see various other file exchange submissions, most notably https://de.mathworks.com/matlabcentral/fileexchange/48155-convert-between-rgb-and-color-names
Examples:
string input
>> rgb = makergb("orange")
rgb =
1.0000 0.5000 0
>> rgb = makergb("m"+(1:4)) % Matlab's first four default colors
rgb =
0 0.4470 0.7410
0.8500 0.3250 0.0980
0.9290 0.6940 0.1250
0.4940 0.1840 0.5560
char or cell array input
>> rgb = makergb(char('red','green','blue'))
rgb =
1 0 0
0 1 0
0 0 1
>> rgb = makergb({'red','green','blue','purple'})
rgb =
1 0 0
0 1 0
0 0 1
0.5 0 0.5
multidimensional input
>> rgb = makergb(["r","g";"y","k"])
rgb(:,:,1) = rgb(:,:,2) = rgb(:,:,3) =
1 0 0 1 0 0
1 0 1 0 0 0
mixed input color representations with a missing value, default set to white
>> [rgb,tfi] = makergb({'r',[0 1 0],'0000ff',"#F0F",[]}, 'w')
rgb =
1 0 0
0 1 0
0 0 1
1 0 1
1 1 1
tfi =
1×5 logical array
1 1 1 1 0
Zitieren als
Andres (2024). makergb (https://www.mathworks.com/matlabcentral/fileexchange/95168-makergb), MATLAB Central File Exchange. Abgerufen.
Kompatibilität der MATLAB-Version
Erstellt mit
R2021a
Kompatibel mit allen Versionen
Plattform-Kompatibilität
Windows macOS LinuxTags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Live Editor erkunden
Erstellen Sie Skripte mit Code, Ausgabe und formatiertem Text in einem einzigen ausführbaren Dokument.
Version | Veröffentlicht | Versionshinweise | |
---|---|---|---|
3.0.0.1 | updated picture |
||
3.0.0 | added current and previous matlab default colors |
||
1.0.0 |