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.