plotting histogram of 3d data.

6 次查看(过去 30 天)
Farhan Ali
Farhan Ali 2022-4-20
回答: Naga 2024-10-23,7:48
I want to plot catagorical histogram of following 3d data.
MATRIX 1
Y 48 98 111
Y 33 73 97
Y 65 97 124
Y 73 93 128
MATRIX 2
N 21 74 113
N 40 70 121
N 41 68 107
N 41 68 107
ON A single histogram
kindly help

回答(1 个)

Naga
Naga 2024-10-23,7:48
Hello Farhan
To create a categorical histogram of your 3D data in MATLAB, follow these steps:
  1. Organize the Data: Merge the data from both matrices into a single array, associating each row with its respective category.
  2. 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.

类别

Help CenterFile Exchange 中查找有关 Histograms 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by