plotting histogram of 3d data.

19 ビュー (過去 30 日間)
Farhan Ali
Farhan Ali 2022 年 4 月 20 日
回答済み: Naga 2024 年 10 月 23 日
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 日
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 Center および File ExchangeHistograms についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by