IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
cellcolor.m
Go to the documentation of this file.
1 %>@ingroup string htmlgen
2 %>@file
3 %>@brief Calculates a background color based on percentage
4 %>
5 %> Sqrt improves the color representation, because it makes low values already some color
6 %> Color formula is:
7 %> - Red: maximum;
8 %> - Green and blue: sqrt(value)/sqrt(sum of row)
9 %
10 %> @param n intensity
11 %> @param ma Maximum
12 %> @param flag_hex =0. If true, returns hexadecimal strings to insert into HTML code, otherwise returns 3-element vectors containing the RGB intensities.
13 %> @return [bgcolor] or [bgcolor, fgcolor]
14 function varargout = cellcolor(n, ma, flag_hex)
15 
16 if ~exist('flag_hex', 'var')
17  flag_hex = 0;
18 end;
19 
20 ma = sqrt(ma);
21 if ma == 0
22  ma = 1;
23 end;
24 
25 n(isnan(n)) = 0;
26 
27 if 1
28  bgcolor = [1, [1, 1]*(1-sqrt(n)/ma)];
29 else
30  bgcolor = [1, 1, 1];
31 end;
32 fgcolor = 1-bgcolor;
33 
34 if flag_hex
35  bgcolor = color2hex(bgcolor);
36  fgcolor = color2hex(fgcolor);
37 end;
38 
39 if nargout == 1
40  varargout = {bgcolor};
41 else
42  varargout = {bgcolor, fgcolor};
43 end;
function cellcolor(in n, in ma, in flag_hex)
function color2hex(in x)