forked from kndiaye/matlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
colorname2rgb.m
64 lines (62 loc) · 1.65 KB
/
colorname2rgb.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
function y = colorname2rgb(x)
%COLORNAME2RGB - Converts colornames to
% [] = colorname(x)
%
% Example
% >> colorname('r')
% [ 1 0 0 ]
% See also:
% Author: K. N'Diaye (kndiaye01<at>yahoo.fr)
% Copyright (C) 2007
% This program is free software; you can redistribute it and/or modify it
% under the terms of the GNU General Public License as published by the
% Free Software Foundation; either version 2 of the License, or (at your
% option) any later version: http://www.gnu.org/copyleft/gpl.html
%
% ----------------------------- Script History ---------------------------------
% KND 2007-10-02 Creation
%
% ----------------------------- Script History ---------------------------------
if isnumeric(x)
y=x;
return;
end
if iscell(x)
y=cell(size(x));
for i=1:numel(x)
y{i}=colorname2rgb(x{i});
end
return
end
if ischar(x)
if size(x,1) >1
y=NaN*zeros(size(x,1),3);
for i=1:size(x,1)
y(i,:)=colorname2rgb(x(i,:));
end
else
switch lower(x)
case { 'k' 'black'}
y=[0 0 0];
case { 'w' 'white'}
y=[1 1 1];
case { 'r' 'red'}
y=[1 0 0];
case { 'g' 'green'}
y=[0 1 0];
case { 'b' 'blue'}
y=[0 0 1];
case { 'y' 'yellow'}
y=[1 1 0];
case { 'c' 'cyan'}
y=[0 1 1];
case { 'm' 'magenta'}
y=[1 0 1];
otherwise
y=str2num(x)
end
end
end
if isempty(y)
y=NaN;
end