function plotConfMatrix(labelStr, M, M_old)
imRows = 60;
imCols = 210;
confImg = zeros(imRows,imCols);
nClasses = numel(labelStr);

for r=1:nClasses
    for c=1:nClasses
        imR = [1:imRows/3]+(r-1)*imRows/3;
        imC = [1:imCols/3]+(c-1)*imCols/3;
        [gR gC] = meshgrid(imR,imC);
        idx = sub2ind([imRows, imCols], gR, gC);
        confImg(idx) = ones(imRows/3,imCols/3) * M(r,c)/sum(M(r,:));
    end
end
% imagesc(confImg);
imshow(confImg);
myColorMap = hot;
myColorMap = myColorMap(end:-1:1, :);
colormap(myColorMap);
hold on
for r=1:nClasses
    for c=1:nClasses
        imR = mean([1,imRows/3]+(r-1)*imRows/3);
        imC = mean([1,imCols/3]+(c-1)*imCols/3);
        colour =  [1 1 1]-myColorMap(1+floor(size(myColorMap,1)*M(r,c)/sum(M(r,:))),:);
        if nargin>2
            str = sprintf('%d(%d)', M(r,c), M_old(r,c));
        else
            str = sprintf('%d', M(r,c));
        end
        text(imC, imR, str, 'Color',colour, 'HorizontalAlignment', 'center')
    end
end
set(gca,'Visible','on')
title('Confusion Matrix','FontSize', 12)
xlabel('result','FontSize', 11)
ylabel('truth','FontSize', 11)

set(gca,'XTick', [imCols/6 imCols/2 5*imCols/6])
set(gca,'XTickLabel', labelStr)

set(gca,'YTick', [imRows/6 imRows/2 5*imRows/6])
set(gca,'YTickLabel', labelStr)

fprintf('Mean accuracy = %g\n', 100*mean(diag(M)./sum(M,2)));
% oldMeanAcc = 100*mean(diag(M_old)./sum(M_old,2))

end