plotting histogram of 3d data.

조회 수: 18 (최근 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 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