3 %>@brief Transforms matrix into a
string
4 %> @todo no longer managing rejected properly
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)
12 if ~exist(
'collabels',
'var') || isempty(collabels)
13 collabels = rowlabels;
16 if ~exist('flag_perc', 'var') || isempty(flag_perc)
17 flag_perc = sum(CC(:)-floor(CC(:))) > 0;
21 flag_rejected = any(CC(:, 1) > 0);
23 collabels = ['rejected', collabels];
29 CC = round(CC*10000)/100; % To make 2 decimal places only
32 W = 7; % the "7" could be more accurately resolved
33 % wids = W*ones(1, nc);
35 wids(i) = max(length(collabels{i}), W);
40 wid1 = max(wid1, length(collabels{i}));
43 spaces = char(32)*ones(1, max([wids, wid1]));
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)];
52 s = [32*ones(1, wid1),
' '];
54 for i =
iif(flag_rejected, 1, 2):nc
55 s_ = [spaces collabels{i}];
56 s = [s
' ' s_(end-wids(i)+1:end)];
61 s_ = [rowlabels{i} spaces];
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)];
function iif(in cond, in x1, in x2)
function confusion_str(in CC, in rowlabels, in collabels, in flag_perc)