IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
html_confusion.m
Go to the documentation of this file.
1 %>@ingroup string htmlgen
2 %>@file
3 %>@brief Transforms matrix into HTML
4 %>
6 
7 %> @param CC confusion matrix (first column always represents "rejected" items)
8 %> @param rowlabels row labels
9 %> @param collabels=rowlabels column labels
10 %> @param flag_perc=0
11 %> @param flag_rejected=(auto-detect)
12 %> @param flag_color=1 Whether to use colors for cell background. If true, will paint the background with a red gradient which is
13 %> @param SS Standard deviations (optional)
14 %> proportional to the square root of the number inside divided by the square root of the corresponding row sum.
15 %> @return s A string
16 function s = html_confusion(CC, rowlabels, collabels, flag_perc, flag_rejected, flag_color, SS)
17 
18 if ~exist('collabels', 'var') || isempty(collabels)
19  collabels = rowlabels;
20 end;
21 
22 if ~exist('flag_perc', 'var') || isempty(flag_perc)
23  flag_perc = 0;
24 end;
25 
26 [ni, nj] = size(CC);
27 
28 if ~exist('flag_rejected', 'var') || isempty(flag_rejected)
29  flag_rejected = any(CC(:, 1) > 0);
30 end;
31 
32 if ~exist('flag_color', 'var') || isempty(flag_color)
33  flag_color = 1;
34 end;
35 
36 
37 if ~exist('SS', 'var')
38  SS = [];
39 end;
40 flag_std = ~isempty(SS);
41 
42 sperc = '';
43 if flag_perc
44  sperc = '%';
45  CC = round(CC*100)/100; % To make 2 decimal places only
46 
47  if flag_std
48  SS = round(SS*100)/100;
49  end;
50 end;
51 
52 
53 % Makes table header
54 c = {'&nbsp'};
55 if flag_rejected; c = [c, 'rejected']; end;
56 c = [c, collabels];
57 h = arrayfun(@(s) ['<td class="tdhe">', s{1}, '</td>'], c, 'UniformOutput', 0);
58 s = ['<table>', 10, '<tr>', strcat(h{:}), '</tr>', 10];
59 
60 h = cell(1, nj);
61 for i = 1:ni
62  if flag_perc
63  ma = 100;
64  else
65  ma = sum(CC(i, :));
66  end;
67 
68  k = 0; % graphics column (whereas j is the matrix column)
69  for j = iif(flag_rejected || ni == nj, 1, 2):nj % column loop
70  k = k+1;
71  n = CC(i, j);
72  if ~flag_color
73  bgcolor = 'FFFFFF';
74  fgcolor = '000000';
75  else
76  [bgcolor, fgcolor] = cellcolor(n, ma, 1);
77  end;
78 
79  if flag_std
80  sfrag = ['&plusmn;', num2str(SS(i, j)), sperc];
81  else
82  sfrag = '';
83  end;
84 
85  h{k} = ['<td class="tdnu" style="color: #', fgcolor, '; background-color: #', bgcolor, ';">', num2str(n), sperc, ...
86  sfrag, '</td>'];
87  end;
88 
89  s = cat(2, s, ['<tr><td class="tdle">', rowlabels{i}, '</td>', strcat(h{:}), '</tr>', 10]);
90 end;
91 s = cat(2, s, '</table>', 10);
function html_comparison_std(in M, in S, in labels, in B, in cornerstr)
function html_confusion(in CC, in rowlabels, in collabels, in flag_perc, in flag_rejected, in flag_color, in SS)
function html_table_std(in M, in S, in rowlabels, in collabels, in B, in cornerstr)
function html_comparison(in M, in labels, in B, in cornerstr)
function html_table_std_colors(in M, in S, in rowlabels, in collabels, in cornerstr, in minimum, in maximum, in pow)
function cellcolor(in n, in ma, in flag_hex)
function iif(in cond, in x1, in x2)