필터 지우기
필터 지우기

3D Confusion Matrix

조회 수: 18 (최근 30일)
Sansit Das
Sansit Das 2020년 4월 20일
답변: Jaswanth 2024년 7월 26일 9:46
I want to make a 3D confusion matrix. I made a 2D confusion matrix using the plotConfMat.m file from file exchange. My x,y and z axis have fixed values(i.e., 1,2,3,4,5).
if x==y | y==z | x==z
then
no_value;
%Ex: a(1,1,1) = no_value;
%a(1,1,2) = no_value;
else
value;
%Ex:a(1,2,3) = 2.22;
%a(2,3,4) = 3.27;
and so on.
Can anyone help me how to do a 3D confusion matrix? I have gone through confusionMatrix3d.m file from file exchange, but I do not want a bar chart.

답변 (1개)

Jaswanth
Jaswanth 2024년 7월 26일 9:46
Hi Sansit,
To create a 3D confusion matrix in MATLAB, you can start by defining the matrix dimensions and initializing it with NaN values to represent no_value where (x = y) or (y = z) or (x = z).
Next, assign specific values to the elements where (x \neq y \neq z). Finally, visualize the matrix using scatter3 function (since you prefer not to use bar chart) to create a 3D scatter plot, which effectively displays the non-NaN values. This approach ensures that your matrix adheres to the specified conditions and provides a clear and accurate visualization.
Please refer to the following example code demonstrating the implementation discussed above:
% Define the dimensions
dims = 5;
% Initialize the 3D matrix with NaN (as no_value)
confMat3D = NaN(dims, dims, dims);
% Loop through each element and assign values
for x = 1:dims
for y = 1:dims
for z = 1:dims
if x ~= y && y ~= z && x ~= z
% Assign a specific value for demonstration purposes
confMat3D(x, y, z) = rand(); % Replace rand() with your actual value
end
end
end
end
% Visualize the 3D matrix using scatter3
[x_vals, y_vals, z_vals] = ind2sub(size(confMat3D), find(~isnan(confMat3D)));
values = confMat3D(~isnan(confMat3D));
figure;
scatter3(x_vals, y_vals, z_vals, 100, values, 'filled');
colorbar;
xlabel('X-axis');
ylabel('Y-axis');
zlabel('Z-axis');
title('3D Confusion Matrix');
I hope the information provided above is helpful.

카테고리

Help CenterFile Exchange에서 Discrete Data Plots에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by