MATLAB: Cell Array storing RGB

cell arrayrgbtext;

I am storing color short names in a cell array as follows:
color{i,j} = 'r';
Then I'd like to use this cell array to set the color properties of some texts as follows:
text('String', d{i,j},'Units', 'Points',...
'FontSize', 8, 'HorizontalAlignment', 'right', ...
'Color', color(i,j));
However, I get the error "Color value must be a 3 element numeric vector". I have tried using a function that convert the short name of colors to their RGB triplet, but it seems that color(i,j) does not output a string/char. How should I go about this? Thank you.

Best Answer

If you are doing one at a time, then color{i,j} gets to the character.
If you were trying to do a whole bunch of them, such as to name the colors for each point of scatter3, then a lookup table is probably easiest.
RGBtab = [0 0 1; 0 1 0; 0 0 0; 1 0 0]; %RGB codes for colors
colorabbr = {'b', 'g', 'k', 'r'}; %must match order of RGB triple rows
[tf, idx] = ismember(color(:), colorabbr); %look up codes to find index
colorrgb = RGBtab(idx,:); %convert to RGB triples
and now colorrgb would be an N x 3 of RGB. If you needed to you could
reshape(colorrgb, size(color,1), size(color,2), 3)
to get a truecolor array