How plot a matrix for Naive Bayes classifier?

Bajdar Nour · Apr 14, 2022 · 1.9K views
Question
I want to illustrate the matrix as shown in the picture this is a part of the code fh = figure('Name', 'Confusion matrix', ... 'NumberTitle', 'off'); plotmat(cMat1, 'k', 'k', 15); title(['Classification rate: ' num2str(classificationrate) '% for Naive Bayes Classifier'], 'FontSize', 14); but it says Undefined function or variable 'plotmat'.   does has   any function instead plotmat?  
Expert Answer
Profile picture of John Michell
John Michell PhD Expert
Answered Aug 24, 2026

The heatmap function was introduced in 2017a. The imagesc function will work though. To display the numeric counts you will require a little more work with the text function requiring the location of the text and the x-y data points where the text should appear.

 

A = randi([0,20],5,5);
imagesc(A);

% Find the x, y locations for the text
x = 1:size(A,2);
y = 1:size(A,1);
% Grid of X,Y locations:
[X,Y] = meshgrid(x,y);

% Convert numbers in matrix to cell array of chars
c = cellfun(@num2str,num2cell(A),'UniformOutput',false);
% Palce text labels at X,Y lcoations:
text(X(:),Y(:),c(:),'HorizontalAlignment','center');
% Add a colorbar
colorbar

This is basically what heatmap does by default, so upgrading makes things quite a bit easier.

100% Run Guarantee 3-Hour Fast-Track Delivery

Need a Custom Version or Complete Simulation for This Problem?

Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.

Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!