如何避免在混淆矩阵中显示零值 [英] How to avoid displaying zero-values in confusion matrix
本文介绍了如何避免在混淆矩阵中显示零值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用但是,只要单元格上有零,它仍会显示.如何消除单元格上的0.00
印刷?
However whenever there is a zero on the cell it is still shown. How can I eliminate the printing of 0.00
's on the cells?
我的困惑矩阵样本
推荐答案
删除所有空格后,找到'0.00'
并再次用空格替换
After you removed all spaces, find '0.00'
and substitute it with spaces again
idx = find(strcmp(textStrings(:), '0.00'));
textStrings(idx) = {' '};
完整的代码将是:
mat = rand(5); %# A 5-by-5 matrix of random values from 0 to 1
mat(3,3) = 0; %# To illustrate
mat(5,2) = 0; %# To illustrate
imagesc(mat); %# Create a colored plot of the matrix values
colormap(flipud(gray)); %# Change the colormap to gray (so higher values are
%# black and lower values are white)
textStrings = num2str(mat(:),'%0.2f'); %# Create strings from the matrix values
textStrings = strtrim(cellstr(textStrings)); %# Remove any space padding
%% ## New code: ###
idx = find(strcmp(textStrings(:), '0.00'));
textStrings(idx) = {' '};
%% ################
[x,y] = meshgrid(1:5); %# Create x and y coordinates for the strings
hStrings = text(x(:),y(:),textStrings(:),... %# Plot the strings
'HorizontalAlignment','center');
midValue = mean(get(gca,'CLim')); %# Get the middle value of the color range
textColors = repmat(mat(:) > midValue,1,3); %# Choose white or black for the
%# text color of the strings so
%# they can be easily seen over
%# the background color
set(hStrings,{'Color'},num2cell(textColors,2)); %# Change the text colors
set(gca,'XTick',1:5,... %# Change the axes tick marks
'XTickLabel',{'A','B','C','D','E'},... %# and tick labels
'YTick',1:5,...
'YTickLabel',{'A','B','C','D','E'},...
'TickLength',[0 0]);
这给出了:
这篇关于如何避免在混淆矩阵中显示零值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文