IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
confusion_str.m
Go to the documentation of this file.
1 %>@ingroup string
2 %>@file
3 %>@brief Transforms matrix into a string
4 %> @todo no longer managing rejected properly
5 
6 %> @param CC confusion matrix (first column is "rejected")
7 %> @param rowlabels row labels
8 %> @param collabels=rowlabels column labels
9 %> @param flag_perc=(auto-detect)
10 function s = confusion_str(CC, rowlabels, collabels, flag_perc)
11 
12 if ~exist('collabels', 'var') || isempty(collabels)
13  collabels = rowlabels;
14 end;
15 
16 if ~exist('flag_perc', 'var') || isempty(flag_perc)
17  flag_perc = sum(CC(:)-floor(CC(:))) > 0;
18 end;
19 
20 [nr, nc] = size(CC);
21 flag_rejected = any(CC(:, 1) > 0);
22 
23 collabels = ['rejected', collabels];
24 
25 sperc = '';
26 
27 if flag_perc
28  sperc = '%';
29  CC = round(CC*10000)/100; % To make 2 decimal places only
30 end;
31 
32 W = 7; % the "7" could be more accurately resolved
33 % wids = W*ones(1, nc);
34 for i = 1:nc
35  wids(i) = max(length(collabels{i}), W);
36 end;
37 
38 wid1 = 0;
39 for i = 1:nr
40  wid1 = max(wid1, length(collabels{i}));
41 end;
42 
43 spaces = char(32)*ones(1, max([wids, wid1]));
44 
45 
46 % % % % % % % % % % % % % % % % % % % % % % % col_width = (widcols+1)*no_classes+maxlen+1; % +1 for vert spaces; +1 for '\n'
47 % % % % % % % % % % % % % % % % % % % % % % % nr = no_classes+1;
48 % % % % % % % % % % % % % % % % % % % % % % s = [char(32)*ones(1, widcol1) ' '];
49 % % % % % % % % % % % % % % % % % % % % % % s_ = [spaces2 'reject'];
50 % % % % % % % % % % % % % % % % % % % % % % s = [s, s_(end-widcols+1:end)];
51 
52 s = [32*ones(1, wid1), ' '];
53 
54 for i = iif(flag_rejected, 1, 2):nc
55  s_ = [spaces collabels{i}];
56  s = [s ' ' s_(end-wids(i)+1:end)];
57 end;
58 s = [s char(10)];
59 
60 for i = 1:nr
61  s_ = [rowlabels{i} spaces];
62  s = [s s_(1:wid1)];
63  for j = iif(flag_rejected, 1, 2):nc
64  s_ = [spaces sprintf('%6.2f', CC(i, j)) sperc];
65  s = [s ' ' s_(end-wids(j)+1:end)];
66  end;
67  s = [s char(10)];
68 end;
function iif(in cond, in x1, in x2)
function confusion_str(in CC, in rowlabels, in collabels, in flag_perc)