Newer
Older
masterarbeit / CD / matlabCode / plotCM.m
@Jan-Peter Hohloch Jan-Peter Hohloch on 22 Nov 2016 778 bytes final
function [fig] = plotCM(cm,figureTitle)
% plotCM plots a confusion matrix with the given title
    imagesc(squeeze(mean(cm,1)))
    colorbar();
    fig=gcf;
    axes =gca;
    if size(cm,2)==5
        axes.YAxis.TickLabels={'Rest','1','2','3','4'};
        axes.YAxis.TickValues=[1,2,3,4,5];
        axes.XAxis.TickLabels={'Rest','1','2','3','4'};
        axes.XAxis.TickValues=[1,2,3,4,5];
    elseif size(cm,2)==4
        axes.YAxis.TickLabels={'1','2','3','4'};
        axes.YAxis.TickValues=[1,2,3,4];
        axes.XAxis.TickLabels={'1','2','3','4'};
        axes.XAxis.TickValues=[1,2,3,4];
    else
        error('CM has neither 5 nor 4 entries - change plotCM to match your needs')
    end
    xlabel('classified as')
    ylabel('actual class')
    title(figureTitle)
end