function confusionMatrix_print(cm, classnames);
% Pretty-prints a confusion matrix with textual names for classes
%
%
% Inputs:
%
%   cm - the confusion matrix
%
%   classnames - names of the classes.
%

legstr = {};   % legend strings.

capt = '          ';
for ic = 1:length(classnames)
    capt = [capt sprintf('%10s', classnames{ic})];
end

tots = ['          ' sprintf(' %4d/%-4d', [diag(cm)'; sum(cm)])];
accs = ['          ' sprintf(' %7.2f %%', 100 * diag(cm)' ./ sum(cm))];

disp(capt);

for ir = 1:length(classnames)
    s = sprintf('%10s', classnames{ir});
    for ic = 1:length(classnames)
        s = sprintf('%s%10d',s, cm(ir,ic));
    end
    disp(s);
end

disp(tots);
disp(accs);
