Skip to content

Commit

Permalink
Moved colorBrewer so it can be accessed from command line and added t…
Browse files Browse the repository at this point in the history
…he missing function colorspec2rgb, relating to Issue #24
  • Loading branch information
drsewilliams committed Feb 3, 2021
1 parent a8847bf commit 1a1498b
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
File renamed without changes.
54 changes: 54 additions & 0 deletions private/colorspec2rgb.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
function rgb = colorspec2rgb(c)
% COLORSPEC2RGB converts a colorspec to truecolor.
% Usage:
% rgb = colorspec2rgb(c)
% Where:
% c is a color - either rgb or any of the letters in 'rgbwcmyk'
%
% COLORSPEC2RGB converts a character colorspec into a truecolor rgb
% representation. If c is not a character then it is returned as rgb - so
% that it will not affect index or truecolor variables that are input.
%
% Author: Nick Linton (2011)
% Modifications -


rgbspec = [1 0 0;0 1 0;0 0 1;1 1 1;0 1 1;1 0 1;1 1 0;0 0 0];
cspec = 'rgbwcmyk';

% Deal with string color specifications.
if ischar(c),
k = find(cspec==c(1));
if isempty(k)
error('COLORSPEC2RGB: Unknown color string.');
end
if k~=3 || length(c)==1,
rgb = rgbspec(k,:);
elseif length(c)>2,
if strcmpi(c(1:3),'bla')
rgb = [0 0 0];
elseif strcmpi(c(1:3),'blu')
rgb = [0 0 1];
else
error('COLORSPEC2RGB: Unknown color string.');
end
end
elseif isreal(c) && size(c,2)==3
rgb = c;
else
error('COLORSPEC2RGB: Unknown color format.');
end














0 comments on commit 1a1498b

Please sign in to comment.