Hello Farhan
To create a categorical histogram of your 3D data in MATLAB, follow these steps:
- Organize the Data: Merge the data from both matrices into a single array, associating each row with its respective category.
- Plot the Histogram: Use MATLAB's 'histogram' function to visualize the data.
% Data from Matrix 1
data1 = [48, 98, 111; 33, 73, 97; 65, 97, 124; 73, 93, 128];
category1 = repmat({'Y'}, size(data1, 1), 1);
% Data from Matrix 2
data2 = [21, 74, 113; 40, 70, 121; 41, 68, 107; 41, 68, 107];
category2 = repmat({'N'}, size(data2, 1), 1);
% Combine data and categories
data = [data1; data2];
categories = [category1; category2];
% Step 2: Plot the Histogram
% Flatten the data and categories for histogram plotting
flattenedData = data(:);
flattenedCategories = repmat(categories, 1, size(data, 2));
flattenedCategories = flattenedCategories(:);
% Create a categorical array
categoricalData = categorical(flattenedCategories);
% Plot the histogram
figure;
histogram(categoricalData, 'DisplayStyle', 'bar', 'FaceColor', 'b');
xlabel('Category');
ylabel('Frequency');
title('Categorical Histogram of 3D Data');
This script will generate a categorical histogram where the categories 'Y' and 'N' appear on the x-axis, and the frequency of each category is displayed on the y-axis.