Wednesday, August 31, 2011

Hex code for Colormap, matlab

I wanted to set the color code for the table to match with that of the figure.

colormap(jet(33))
labels = {'0','1','2','3'};
lcolorbar(labels,'fontweight','bold')
map2 = colormap; map2( 1, : ) = 1; colormap(map2)
cmap = colormap; % cmap nicely puts colormap into 3 col data

perCmap= (single(round(cmap.*255))); % convert to 255 scale
% You can use one of these options:
colorcell = ['rgb(' num2str(perCmap(1,1)), ',', num2str(perCmap(1,2)), ',', num2str(perCmap(1,3)) ')']

colorcell = ['#' (dec2hex(perCmap(1,1))), dec2hex(perCmap(1,2)), dec2hex(perCmap(1,3)) ]
% the second worked best for me

% I then set it to fid1 for txt file, which I was writing.
<td style="color:#ffffff" bgcolor="%s">
% where %s was the string set as colorcell for open fid fprintf(fid1,'<h1>%s <td/h1>', htmlH1);