how to represent clusters graphicaly ?

조회 수: 1 (최근 30일)
zyad
zyad 2014년 3월 12일
답변: Prateekshya 2024년 10월 14일
hi,i want to implement LDA algorithm ,for a first step i want to have a graphical representation of clusters for example:represent those 2 groups X1=[4,2;2,4;2,3;3,6;4,4] and X2=[9,10;6,8;9,5;8,7;10,8] and X3=[......] with different colors in one graph? like in picture

답변 (1개)

Prateekshya
Prateekshya 2024년 10월 14일
Hello Zyad,
To graphically represent clusters using MATLAB, you can plot each group of data points with a different color. This will help you visualize how the data is distributed before applying the Linear Discriminant Analysis (LDA) algorithm. Here is how you can plot the example groups , , and with different colors:
% Define the data points for each group
X1 = [4, 2; 2, 4; 2, 3; 3, 6; 4, 4];
X2 = [9, 10; 6, 8; 9, 5; 8, 7; 10, 8];
X3 = [5, 5; 6, 5; 7, 6; 5, 7; 6, 6]; % Example data for X3
% Create a new figure
figure;
hold on; % Hold on to plot multiple groups on the same graph
% Plot each group with a different color and marker
plot(X1(:, 1), X1(:, 2), 'ro', 'MarkerSize', 8, 'DisplayName', 'Group X1'); % Red circles
plot(X2(:, 1), X2(:, 2), 'bs', 'MarkerSize', 8, 'DisplayName', 'Group X2'); % Blue squares
plot(X3(:, 1), X3(:, 2), 'g^', 'MarkerSize', 8, 'DisplayName', 'Group X3'); % Green triangles
% Add labels and legend
xlabel('Feature 1');
ylabel('Feature 2');
title('Graphical Representation of Clusters');
legend show; % Display the legend
grid on;
axis equal; % Ensure equal scaling of axes
hold off; % Release the hold on the current figure
The output of the code looks like:
I hope this helps!

카테고리

Help CenterFile Exchange에서 Statistics and Machine Learning Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by