matlab代码花混淆矩阵
时间: 2023-12-28 18:25:36 浏览: 28
以下是在Matlab中绘制混淆矩阵的示例代码:
```matlab
% 创建真实类别和预测类别的向量
trueLabels = [1, 2, 1, 3, 2, 1, 3];
predictedLabels = [1, 2, 1, 1, 2, 3, 3];
% 计算混淆矩阵
confusionMatrix = confusionmat(trueLabels, predictedLabels);
% 绘制混淆矩阵
figure;
heatmap(confusionMatrix, 'Colormap', 'gray', 'ColorbarVisible', 'off', 'FontSize', 12, 'XLabel', 'Predicted Class', 'YLabel', 'True Class');
title('Confusion Matrix');
```
这段代码首先创建了真实类别和预测类别的向量,然后使用`confusionmat`函数计算混淆矩阵。最后,使用`heatmap`函数绘制混淆矩阵,并设置一些参数来美化图表。